Skip to content

fix(v3): return error to frontend as dedicated Error objects instead of stringified JSON - #5690

Merged
leaanthony merged 8 commits into
wailsapp:masterfrom
mbaklor:runtime-error
Jul 6, 2026
Merged

leaanthony merged 8 commits into
wailsapp:masterfrom
mbaklor:runtime-error

Conversation

@mbaklor

@mbaklor mbaklor commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

It looks like errors created in the backend are sent to the frontend as well formatted JSON, but the frontend binding call always extracted it as await response.text(), so I check for the json header and parse it accordingly. Might be worth checking for the CallError.Kind or something but I hit circular dependencies and figured I'd leave it up to discussion.

Fixes # (issue)

Type of change

Please select the option that is relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration using wails doctor.

  • Windows
  • macOS
  • Linux

If you checked Linux, please specify the distro and version.

Test Configuration

Please paste the output of wails doctor. If you are unable to run this command, please describe your environment in as much detail as possible.

Checklist:

  • (v2 only) I have updated website/src/pages/changelog.mdx with details of this PR (v3 changelog entries are added automatically)
  • My code follows the general coding style of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Summary by CodeRabbit

  • Bug Fixes

    • Fixed a frontend bindings parsing issue where responses were always treated as plain text instead of honoring the actual content type.
    • Improved desktop runtime error handling: when failures return JSON (application/json), errors are decoded into structured error information (including selecting an error type and preserving cause). Non-JSON failures still surface the full response text.
  • Documentation

    • Expanded bindings method error-handling docs with examples, including error.cause structured error data and the MarshalError option for customizing error JSON serialization.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

runtimeCallWithID now parses JSON error responses into typed runtime errors and falls back to raw text for non-JSON responses. RuntimeError is exported from runtime.ts, removed from calls.ts, the bindings docs expand error handling guidance, and the unreleased changelog records the fix.

Changes

Runtime error handling and docs

Layer / File(s) Summary
Error payload parsing and export cleanup
v3/internal/runtime/desktop/@wailsio/runtime/src/runtime.ts, v3/internal/runtime/desktop/@wailsio/runtime/src/calls.ts
Adds a structured call error payload type, exports RuntimeError from runtime.ts, updates runtimeCallWithID to branch on Content-Type and throw JSON-backed runtime errors, and removes the local RuntimeError definition from calls.ts.
Bindings error handling docs
docs/src/content/docs/features/bindings/methods.mdx
Reworks the method-call error handling docs to describe runtime error classes, name/message/cause, structured error data, and MarshalError.
Changelog entry
v3/UNRELEASED_CHANGELOG.md
Adds a fixed note for the frontend bindings parsing issue.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested labels: Documentation, runtime, v3-alpha, size:L

Suggested reviewers: leaanthony

Poem

🐇 I sniffed the headers, text or JSON bright,
The runtime hopped to errors that feel just right.
Docs now explain the cause with care,
And changelog carrots sit neatly there.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The template is mostly followed, but the required issue reference is still a placeholder and the testing section lacks concrete reproduction details. Replace the placeholder with the actual Fixes #issue link and add specific test steps plus any wails doctor output or environment details.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: backend errors are now surfaced as structured error objects instead of stringified JSON.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@v3/internal/runtime/desktop/`@wailsio/runtime/src/runtime.ts:
- Around line 145-149: The JSON error handling in runtime.ts currently reads
json.message, but this codebase’s error payloads use an error field, so the
branch can still throw an undefined message. Update the response handling in the
runtime request path to use json.error when available, and fall back to
response.text() if the JSON body doesn’t contain a usable error value. Keep the
change localized to the response.json() / Error throw logic so the runtime
behavior remains consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f19db6a7-cf65-4e39-9cbb-526fdd852050

📥 Commits

Reviewing files that changed from the base of the PR and between cce97f8 and b579c2c.

📒 Files selected for processing (2)
  • v3/UNRELEASED_CHANGELOG.md
  • v3/internal/runtime/desktop/@wailsio/runtime/src/runtime.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@v3/internal/runtime/desktop/`@wailsio/runtime/src/calls.ts:
- Line 12: The public Call namespace is losing RuntimeError because calls.ts
only imports it as a type, so the value is not re-exported through src/index.ts.
Update the runtime/calls export path to re-export RuntimeError from runtime.ts
as a value alongside newRuntimeCaller and objectNames, and keep the Call
namespace API intact so Call.RuntimeError remains available from
`@wailsio/runtime`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4880c6ef-78ea-42a8-a8e3-f8947d7c994d

📥 Commits

Reviewing files that changed from the base of the PR and between 02c9496 and be4ac20.

📒 Files selected for processing (2)
  • v3/internal/runtime/desktop/@wailsio/runtime/src/calls.ts
  • v3/internal/runtime/desktop/@wailsio/runtime/src/runtime.ts

@mbaklor mbaklor changed the title fix(bindings): returned error parsed as text instead of json fix(v3): returned error parsed as Error object instead of json Jul 5, 2026
@mbaklor mbaklor changed the title fix(v3): returned error parsed as Error object instead of json fix(v3): return error to frontend as dedicated Error objects instead of stringified JSON Jul 5, 2026
Expand the Error Handling section of the method bindings docs to cover
the new behaviour from wailsapp#5690: failed calls reject with TypeError,
RuntimeError or Error based on the error kind reported by the backend,
with the Go error message on .message and the serialised Go error on
.cause. Add a section on returning custom error types and customising
serialisation with ServiceOptions.MarshalError.
@leaanthony
leaanthony enabled auto-merge (squash) July 6, 2026 05:57
@leaanthony
leaanthony disabled auto-merge July 6, 2026 05:58
The bundled runtime is verified against a clean rebuild of the runtime
source by CI, so the calls/runtime changes in this PR need the
regenerated bundles committed alongside them. Built with npm ci +
task runtime:build:assets per .github/workflows/verify-runtime-assets.yml.
@leaanthony
leaanthony merged commit 78254ef into wailsapp:master Jul 6, 2026
39 checks passed
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.

2 participants