Skip to content

fix: forward async data errors to awaiting callers - #12

Merged
3m1n3nc3 merged 1 commit into
mainfrom
fix/async-data-errors
Nov 7, 2026
Merged

3m1n3nc3 merged 1 commit into
mainfrom
fix/async-data-errors

Conversation

@3m1n3nc3

@3m1n3nc3 3m1n3nc3 commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Problem

When a resource's async data() throws, await resource never settles. await only listens to the callbacks passed to then(), but runThen rejected the promise it returned without calling onrejected. The request hung and the error escaped as an unhandled rejection, which crashes the process on Node 15+ instead of reaching Express/H3 error handlers.

This affected Resource, ResourceCollection and GenericResource when awaited directly (or returned from an H3 handler). await resource.response() already worked.

Fix

BaseSerializer.runThen now runs serialization in dispatchThen and chains onfulfilled/onrejected on its result, so errors from data(), withResponse or plugins reach the caller.

Tests

tests/async-errors.spec.ts covers awaiting each serializer, catch(), the Express error middleware (direct await and response()), and the H3 onError handler. Five of these fail (hang) without the fix. Full suite: 241 passing, lint and typecheck clean.

Awaiting a resource only listens to the callbacks passed to then(), so a
rejected serialization left the request hanging and surfaced as an
unhandled rejection instead of reaching the framework's error handler.
@3m1n3nc3 3m1n3nc3 self-assigned this Nov 7, 2026
@codecov

codecov Bot commented Nov 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@3m1n3nc3
3m1n3nc3 merged commit 634f44b into main Nov 7, 2026
4 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.

1 participant