jcpsantiago / sentryR

Unofficial R client for Sentry
https://jcpsantiago.github.io/sentryR/
Other
38 stars 14 forks source link

Files and functions are scrambled in stack traces #25

Closed egnor closed 9 months ago

egnor commented 1 year ago

DISCLAIMER: I'm new to R and could be totally off base. But I believe this code is badly erroneous:

  to_keep <- !(funs %in% c(
    "stop", ".handleSimpleError", "h",
    "doTryCatch", "tryCatchList", "tryCatchOne"
  ))

  funs_to_keep <- funs[to_keep]

  names(srcrefs) <- funs_to_keep
  names(srcfiles) <- funs_to_keep

  srcrefs <- srcrefs[to_keep]

  srcfiles <- srcfiles[to_keep]

  full_function_call <- as.character(calls)
  names(full_function_call) <- funs_to_keep
  full_function_call <- full_function_call[to_keep]

Specifically, to_keep is a boolean vector of the length of the original funs identifying ones to keep; funs_to_keep is a shorter vector of just the kept ones. Reassigning names(srcrefs) <- funs_to_keep before subsetting srcrefs assigns the wrong names to the wrong references; then subsetting them leaves a smattering of nonsense function names. I think it should be:

  full_function_call <- as.character(calls)

  to_keep <- [same as before...]
  funs <- funs[to_keep]
  srcrefs <- srcrefs[to_keep]
  srcfiles <- srcfiles[to_keep]
  full_function_call <- full_function_call[to_keep]

  names(srcrefs) <- funs
  names(srcfiles) <- funs
  names(full_function_call) <- funs

(If you made it into a tibble or dataframe before filtering out uninteresting functions, and then added the extra columns, this would all be a lot easier and less error-prone?)

I suspect this is related to how I'm getting completely wrong source context in my stack traces...?