Skip to content

fix(runtime): raise JavaScriptError for any thrown value, not only Error instances - #675

Merged
route merged 1 commit into
mainfrom
fix/js-exception-details
Oct 23, 2026
Merged

route merged 1 commit into
mainfrom
fix/js-exception-details

Conversation

@route

@route route commented Oct 23, 2026

Copy link
Copy Markdown
Member

handle_error checked the result's subtype instead of exceptionDetails, so:

  • throw "smth", throw { code: 1 } or a promise rejected with a non-Error value were returned as the result of evaluate, execute, evaluate_async and evaluate_on instead of raising
  • returning (not throwing) an Error object crashed with NoMethodError, because JavaScriptError was built from missing exceptionDetails

Now any exceptionDetails raises JavaScriptError (or ScriptTimeoutError for the async timeout), and a returned Error is converted like any other object. For a thrown primitive the message includes the value, e.g. Uncaught smth instead of Uncaught; thrown Errors keep the same class_name, message and stack_trace.

The existing evaluate(%(throw "smth")) spec only passed because the return wrapper made it a syntax error; the new specs throw for real and fail without the fix.

Cuprite's custom JS errors all extend Error, so its behavior doesn't change: session_spec.rb and driver_spec.rb pass against this branch.

…ror instances

handle_error looked at the result's subtype instead of exceptionDetails, so throwing a string or an object returned
it as the result, while returning an Error object crashed with NoMethodError. JavaScriptError's message includes
the thrown primitive, e.g. "Uncaught smth" instead of just "Uncaught".
@route
route merged commit 19f79c3 into main Oct 23, 2026
6 checks passed
@route
route deleted the fix/js-exception-details branch October 23, 2026 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant