Skip to content

Caller misidentification #286

@Enchufa2

Description

@Enchufa2

Caller identification for error printing is made here:

simmer/R/utils.R

Lines 42 to 44 in ca6632e

get_caller <- function(n=1) {
sub("\\.[[:alpha:]]+$", "", as.character(sys.call(-n-1))[[1]])
}

So, for instance, we have this for R 3.6.x as well as 4.0.x:

trajectory() %>% log_(1)
#> Error: log_: 'message' is not a valid character or function

But then, for R 4.1.x:

trajectory() %>% log_(1)
#> Error: check_args: 'message' is not a valid character or function

and R 4.2.x:

trajectory() %>% log_(1)
#> Error: stop: 'message' is not a valid character or function

which means that we cannot rely on a fixed stack position. It's better to perform a (limited) search, e.g.,

get_caller <- function(max.depth=10) {
  for (i in seq_len(max.depth)) {
    fun <- as.character(sys.call(-i-1)[[1]])
    if (grepl("\\.(simmer|trajectory)$", fun))
      return(strsplit(fun, ".", fixed=TRUE)[[1]][1])
  }
  return("")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions