evaluate icon indicating copy to clipboard operation
evaluate copied to clipboard

Teach evaluate about condition handlers

Open jennybc opened this issue 5 years ago • 1 comments

@lionel- and I have talked about this (https://github.com/tidyverse/reprex/issues/320#issuecomment-670358939) but I want to open a specific issue.

Until this happens, rlang::last_error() and rlang::last_trace() don't work, in general, in knitr and, therefore, in reprex. We can still do options("rlang:::force_unhandled_error" = TRUE) on a case-by-case basis, but @lionel- feels it does more harm than good if I were to make that global or default reprex behaviour.

jennybc avatar Aug 11 '20 01:08 jennybc

I experimented with this in:

  • https://github.com/lionel-/evaluate/commit/e639b67e260b4aa7a853ca2c409f71bdf4429831
  • https://github.com/lionel-/knitr/commit/61c17f56e623f546c1b20ea9c0e78e4841e21116

lionel- avatar Aug 11 '20 04:08 lionel-

Would also be cool if evaluate could automatically cross-register global error handlers.

hadley avatar Jun 14 '24 18:06 hadley

This was implemented in https://github.com/r-lib/evaluate/pull/105

Would also be cool if evaluate could automatically cross-register global error handlers.

For expected errors you mean, because our try-catch prevents the global handlers from running? hmm... Interesting idea but automatically copying handlers on top of an existing R stack has the potential for unexpected behaviour. We'd need to check whether this has unintended effects with Ark for instance (I think it does). Alternatively we could require the handler to implement some interface that declares it's okay to copy it in nested "repl" contexts.

lionel- avatar Jun 17 '24 06:06 lionel-

Ok great!

Yeah I also realised copying automatically is likely to be fraught. Might instead be better for evaluate to expose its own system for registering handlers. Anyway I’ll keep thinking about it as I work on evaluate.

hadley avatar Jun 17 '24 08:06 hadley