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

Caller misidentification #286

Closed
Enchufa2 opened this issue Jul 15, 2022 · 0 comments
Closed

Caller misidentification #286

Enchufa2 opened this issue Jul 15, 2022 · 0 comments
Labels

Comments

@Enchufa2
Copy link
Member

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("")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant