You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, Rhino wraps native Java exceptions thrown by host functions with the WrappedException class. If a script catches a WrappedException, Rhino exposes an error object to the catch block with a message like "JavaException: java.lang.RuntimeException: exception message". For my use case, users running scripts do not know that their JavaScript code is being executed in Java, so it's confusing that some exception messages are prefixed by "JavaException: (Java class name):".
To allow some Rhino users to avoid exposing implementation details of Java exceptions, while maintaining the current behavior for users who prefer to allow scripts to see details of Java exceptions, one approach could be to add a context feature flag and update ScriptRuntime.newCatchScope like this:
else if (t instanceof WrappedException) {
WrappedException we = (WrappedException) t;
re = we;
javaException = we.getWrappedException();
if (cx.hasFeature(Context.FEATURE_HIDE_WRAPPED_EXCEPTIONS)) {
type = TopLevel.NativeErrors.InternalError;
errorMsg = javaException.getMessage();
} else {
type = TopLevel.NativeErrors.JavaException;
errorMsg = javaException.getClass().getName() + ": " + javaException.getMessage();
}
}
Are there any simpler ways to do this?
I could submit a PR for this if adding a Context feature flag seems like a good approach.
The text was updated successfully, but these errors were encountered:
Currently, Rhino wraps native Java exceptions thrown by host functions with the WrappedException class. If a script catches a WrappedException, Rhino exposes an error object to the catch block with a message like "JavaException: java.lang.RuntimeException: exception message". For my use case, users running scripts do not know that their JavaScript code is being executed in Java, so it's confusing that some exception messages are prefixed by "JavaException: (Java class name):".
This code is implemented in the static function
ScriptRuntime.newCatchScope
(https://github.com/mozilla/rhino/blob/master/src/org/mozilla/javascript/ScriptRuntime.java#L3962). As far as I can tell, it currently doesn't seem possible to override this behavior other than by updating everyjsFunction_
function to catch all exceptions and rethrow EvaluatorException.To allow some Rhino users to avoid exposing implementation details of Java exceptions, while maintaining the current behavior for users who prefer to allow scripts to see details of Java exceptions, one approach could be to add a context feature flag and update
ScriptRuntime.newCatchScope
like this:Are there any simpler ways to do this?
I could submit a PR for this if adding a Context feature flag seems like a good approach.
The text was updated successfully, but these errors were encountered: