klmr / klmr/box

Unexpected error when trying to access non-existent variable from module

Open
#360 3 comments 0 reactions 0 assignees Claimed by @ArcadeAntics View on GitHub
⚠️ bug
Dominant language
R
Stars
979
Forks
49
PR merge metrics
No merged PRs in 30d

Description

### Error description

I tried to access a variable from a module but had mistyped the name, so it tried to throw an error with message `"name '%s' not found in '%s'"`. Instead of doing that, it threw a different error with message `"'Rf_translateChar' must be called on a CHARSXP, but got 'symbol'"` because the C function assumes the first argument is a symbol. As an example:

```R
box::use(utils)
x <- list(utils = utils)
x$utils$test
```

I'm not sure what the exact expected output would be, but any of the following error messages would suffice:

* `stop(sprintf("name '%s' not found in '%s'", "test", "x$utils"))`
* `stop(sprintf("name '%s' not found in '%s'", "test", attr(x$utils, "name")))`
* `stop(sprintf("name '%s' not found in '%s'", "test", attr(x$utils, "spec")$alias))`

That being said, I think your C code to generate such an error is unnecessarily complex, and could be greatly simplified with the use of `.External2` instead of `.Call`. I could submit a PR if you like!

### R version

```plain text
platform x86_64-w64-mingw32
arch x86_64
os mingw32
crt ucrt
system x86_64, mingw32
status
major 4
minor 3.3
year 2024
month 02
day 29
svn rev 86002
language R
version.string R version 4.3.3 (2024-02-29 ucrt)
nickname Angel Food Cake
```

### ‘box’ version

[1] ‘1.2.0’

Contributor guide

Open the contributing guide

Research direction

Reproduce the R example from the issue and inspect the C entry point involved in resolving the non-existent variable, including how .Call receives its arguments. Compare the resulting error with the acceptable not-found messages; note that linked pull request #361 already indicates work is underway.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, r
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.