Skip to content

Error messages do not include a source reference for composite function calls #1874

@iofarm

Description

@iofarm

When abort() is called by a function that is called as an argument to another function, $call does not have a "srcref" attribute and the error does not display the source location.

Compare the output of g1() and g2() in this example:

options(rlang_backtrace_on_error = "none")

script <- tempfile(fileext = ".R")
cat('
f <- function() {
  abort("Something\'s wrong...")
}

g1 <- function() {
  f()
}

g2 <- function() {
  identity(f())
}
', file = script)
source(script)

g1()

#> Error in `f()` at /Rtmp5iDn8E/file8ae03bd8bd93.R:7:3:
#> ! Something's wrong...

g2()

#> Error in `f()`:
#> ! Something's wrong...

This seems to be a limitation in how R does not preserve source references for promise expressions:

h <- \() sys.call() %@% srcref

(\() h())()

#> \() h()

(\() identity(h()))()

#> NULL

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions