Skip to content

fix(runtime): wrap string errors in Error objects in binding callbacks - #5250

Closed
leaanthony wants to merge 1 commit into
masterfrom
v2-bugfix/4379-binding-error-objects
Closed

leaanthony wants to merge 1 commit into
masterfrom
v2-bugfix/4379-binding-error-objects

Conversation

@leaanthony

Copy link
Copy Markdown
Member

Description

Fixes #4379

When a Go binding returns an error, the JS runtime's Callback function rejected the promise with the raw string from Go instead of wrapping it in an Error object. This broke error handling in libraries like TanStack Query that expect rejected values to be Error instances (e.g., error.message was undefined).

Changes

  • In calls.js:Callback(), changed reject(message.error) to reject(typeof message.error === 'string' ? new Error(message.error) : message.error)
  • Updated bundled runtimes (runtime_debug_desktop.js, runtime_prod_desktop.js)
  • Non-string error objects are passed through unchanged for backward compatibility

Testing

  • Added test in v2/test/4379/binding_error_test.js verifying string errors are wrapped in Error, object errors pass through, and success cases still work

When a Go binding returns an error, the JS runtime's Callback function
rejected the promise with the raw string from Go instead of wrapping it
in an Error object. This broke error handling in libraries like TanStack
Query that expect rejected values to be Error instances.

Now wraps string errors in new Error() while passing non-string errors
through unchanged.

Fixes #4379
@coderabbitai

coderabbitai Bot commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 44cce0f7-38a2-439b-8ab9-262a9944ec9b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch v2-bugfix/4379-binding-error-objects

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Frontend bindings does not return "Error" object on errors, only strings

1 participant