Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reportAssertions always reports errors from top level #238

Open
dgkf opened this issue Jan 23, 2023 · 0 comments
Open

reportAssertions always reports errors from top level #238

dgkf opened this issue Jan 23, 2023 · 0 comments

Comments

@dgkf
Copy link

dgkf commented Jan 23, 2023

I'm not sure if this is intentional, but it's a bit confusing.

Raising assertions in x, I would expect that the error message's call originates from x:

x <- function(a) {
  coll <- makeAssertCollection()
  coll$push("whoops!")
  reportAssertions(coll)
}

y <- function(...) x(...)

y()
## Error in y() : 1 assertions failed:
##  * whoops!

Instead, the error is reported as originating in y().

This occurs because the top level call (sys.call(1L)) is used for the error condition instead of the calling frame (sys.call(-1L))

stop(simpleError(paste0(err, collapse = "\n"), call = sys.call(1L)))

For call stacks that span multiple packages, this can give the impression that errors are raised through the surface-level package when they were actually raised by a dependency.

Whether this is intended or not, the option to specify a call provided to reportAssertions would be a nice addition in order to make the error reporting communicate the location where the assertions are raised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant