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

More useful stack traces #16

Open
jcpsantiago opened this issue Apr 3, 2020 · 5 comments
Open

More useful stack traces #16

jcpsantiago opened this issue Apr 3, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@jcpsantiago
Copy link
Owner

https://renkun.me/2020/03/31/a-simple-way-to-show-stack-trace-on-error-in-r/

has some ideas about making stack traces more informative. could be useful for sentryR.

@jcpsantiago jcpsantiago added the enhancement New feature or request label Apr 3, 2020
@egnor
Copy link
Contributor

egnor commented Aug 10, 2023

What in particular could be useful from that post?

@jcpsantiago
Copy link
Owner Author

It shows how to get to the actual functions calls, which what one wants most of the time IMO, otherwise you can't retrace what happened. At the moment, the stack trace in SentryR is created with https://github.com/EduSemensati/sentryR/blob/b4d0767736f7ebc3b4916a078c6c4d0a44d59890/R/calls.R#L12 are not as "clean". So an idea could be to replicate that blog post e.g. in the function that wraps endpoints and /or capture.

I have to be honest, I haven't given this a lot of thought. Mostly because the current stack traces have been "good enough" and nobody else complained, but I'm always open to ideas :D

@egnor
Copy link
Contributor

egnor commented Aug 11, 2023

I'm not sure what you mean about "getting to the actual function calls"? Isn't that what sentryR already does?

There's a few different suggestions in that blog post

  • use traceback, which dumps the current stack to stdout (not really useful here)
  • (sentryR could use .traceback, but really that just walks sys.calls and formats the result)
  • limit the number of stack entries to a small amount (e.g. 3)
  • limit the number of lines printed from each stack entry to a small amount (e.g. 1)
  • write one's own formatter for sys.calls, which is exactly what sentryR does
  • use the rlang package which provides its own stack trace capture handler

At the end of the data everything is just some transformation of the output of sys.calls, which is what sentryR is already doing, so I'm not sure which suggestion you feel like might be helpful.

I actually experimented a bit with rlang and its error handling. It has pretty formatting tools and adds handlers to attach stack chains to errors whenever it sees them. However it wasn't actually super helpful in my case, because the handlers I would use to route errors to Sentry would always come before the rlang handler, which meant I didn't really get extra information.

The biggest problem I've had with sentryR's stack reporting (besides the various bugs I've been reporting!) is that when code uses a tryCatch and then wants to report the error to Sentry, the useful context of the actual error is lost-- you only get the stack up to the tryCatch itself and not to the point that actually signaled the error. To do better one should use withCallingHandlers, and we have our own with_sentry wrapper that does that, but in existing code that's not always feasible to insert.

@apit
Copy link

apit commented Aug 18, 2023

2023-08-18_08-37

why are they so different? i'm very new to R. is this related to #25? I tried gh-29 but i didn't notice any difference.

@egnor
Copy link
Contributor

egnor commented Aug 18, 2023

why are they so different? i'm very new to R. is this related to #25? I tried gh-29 but i didn't notice any difference.

I'm not sure the reason for all the differences-- perhaps something about shiny's control flow model?-- but a big one is that the console is printing the trace at the moment where it happens, but sentryR is getting the trace in the tryCatch handler (an issue noted above).

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

No branches or pull requests

3 participants