webr
webr copied to clipboard
Throwing subclasses of JS `Error` should be converted into classed R conditions (or similar)
When executing JS code from R, throwing a JS Error
raises an R error
condition:
> webr::eval_js("throw new Error('Something bad happened')")
Error in webr::eval_js("throw new Error('Something bad happened')") :
An error occurred during JavaScript evaluation:
Something bad happened
We would like to be able to catch and handle such JS errors on the R side. This can be done currently by handling the R error
condition and string matching on the Error
's message text, but in principle we should be able to match on something constant in the presence of message translation.
I think from JS we should be able to throw subclasses of Error
, and webR should be able to capture that information and convert it into classed R error
conditions, or attach the JS class information to the R condition in some other way so that a particular type of error can be matched in R condition handlers.