klmr / klmr/box

Show a readable error message when there’s an error in a module

Open
#286 0 comments 0 reactions 1 assignee Claimed by @klmr View on GitHub
⚠️ bug
Dominant language
R
Stars
979
Forks
49
PR merge metrics
No merged PRs in 30d

Description

Currently, `box::use()` assumes that any error raised inside it must come from ‘box’ itself, and the error message/traceback is completely useless for module developers if there was an error in the loaded module source code:

### `x.r`

```r
f = function () stop('nope')
f()
```

### …

```r
〉box::use(./x)
Error in box::use(./x) : nope

〉traceback()
12: stop(box_error(message, call = call, subclass = subclass))
11: rethrow(error, call)
10: value[[3L]](cond)
9: tryCatchOne(expr, names, parentenv, handlers[[1L]])
8: tryCatchList(expr, classes, parentenv, handlers)
7: tryCatch(expr, error = function(error) rethrow(error, call))
6: rethrow_on_error({
spec = parse_spec(declaration, alias)
info = find_mod(spec, caller)
load_and_register(spec, info, caller)
}, call = use_call)
5: (function (declaration, alias, caller, use_call)
{
if (identical(declaration, quote(expr = )) && identical(alias,
""))
return()
rethrow_on_error({
spec = parse_spec(declaration, alias)
info = find_mod(spec, caller)
load_and_register(spec, info, caller)
}, call = use_call)
})(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]], use_call = dots[[4L]][[1L]])
4: mapply(FUN = f, ..., SIMPLIFY = FALSE)
3: Map(.f, ..., USE.NAMES = FALSE)
2: map(use_one, imports, aliases, list(caller), use_call = list(sys.call()))
1: box::use(./x)
```

### Expected result

Something along these lines:

```r
〉box::use(./x)
Error in box::use(./x) :
Error in f() : nope

〉traceback()
3: stop("nope") at ./x.r#1
2: f() at ./x.r#2
1: box::use(./x)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.