Skip to content

Comments

feat(napi): add Error.cause support to napi::Error#2829

Merged
Brooooooklyn merged 2 commits intonapi-rs:mainfrom
sapphi-red:feat/error-cause-support
Aug 5, 2025
Merged

feat(napi): add Error.cause support to napi::Error#2829
Brooooooklyn merged 2 commits intonapi-rs:mainfrom
sapphi-red:feat/error-cause-support

Conversation

@sapphi-red
Copy link
Contributor

@sapphi-red sapphi-red commented Aug 4, 2025

Made napi::Error to be able to set the cause property. This can improve the error message when passing the error message generated on the JS side back to the JS side from the Rust side (rolldown/rolldown#5596).

Does this approach look good? If so, I'll a bit more tests.

@graphite-app
Copy link

graphite-app bot commented Aug 4, 2025

How to use the Graphite Merge Queue

Add the label ready-to-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@Brooooooklyn Brooooooklyn changed the title feat: add Error.cause support to napi::Error feat(napi): add Error.cause support to napi::Error Aug 5, 2025
@Brooooooklyn Brooooooklyn merged commit 7f5013e into napi-rs:main Aug 5, 2025
64 checks passed
@github-actions github-actions bot mentioned this pull request Aug 5, 2025
@sapphi-red sapphi-red deleted the feat/error-cause-support branch August 6, 2025 05:16
This was referenced Aug 7, 2025
github-merge-queue bot pushed a commit to rolldown/rolldown that referenced this pull request Aug 28, 2025
Made the `this.resolve` / `this.load` error message to contain the
original stacktrace.

**Old Error**:
```
[plugin test-plugin-context]
Error: Errored while resolving "./sub.js" in `this.resolve`. Got GenericFailure, Error: my error.
```

**New Error**:
```
[plugin test-plugin-context]
Error: Errored while resolving "./sub.js" in `this.resolve`.
Caused by:
  [plugin test-plugin-context]
  Error: my error
      at PluginContextImpl.resolveId (/home/green/workspace/rolldown/packages/rolldown/tests/fixtures/plugin/context/resolve/_config.ts:24:19)
      at plugin (/home/green/workspace/rolldown/packages/rolldown/dist/shared/src-_iWIzySM.mjs:2706:30)
      at plugin.<computed> (/home/green/workspace/rolldown/packages/rolldown/dist/shared/src-_iWIzySM.mjs:3404:18)
```

Related error:
https://github.com/vitejs/vite-ecosystem-ci/actions/runs/16718227301/job/47316318655#step:7:1580

depends on napi-rs/napi-rs#2829
github-merge-queue bot pushed a commit to rolldown/rolldown that referenced this pull request Aug 28, 2025
Made the `this.resolve` / `this.load` error message to contain the
original stacktrace.

**Old Error**:
```
[plugin test-plugin-context]
Error: Errored while resolving "./sub.js" in `this.resolve`. Got GenericFailure, Error: my error.
```

**New Error**:
```
[plugin test-plugin-context]
Error: Errored while resolving "./sub.js" in `this.resolve`.
Caused by:
  [plugin test-plugin-context]
  Error: my error
      at PluginContextImpl.resolveId (/home/green/workspace/rolldown/packages/rolldown/tests/fixtures/plugin/context/resolve/_config.ts:24:19)
      at plugin (/home/green/workspace/rolldown/packages/rolldown/dist/shared/src-_iWIzySM.mjs:2706:30)
      at plugin.<computed> (/home/green/workspace/rolldown/packages/rolldown/dist/shared/src-_iWIzySM.mjs:3404:18)
```

Related error:
https://github.com/vitejs/vite-ecosystem-ci/actions/runs/16718227301/job/47316318655#step:7:1580

depends on napi-rs/napi-rs#2829
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