Skip to content

Fix: Report fetch and HTTP errors when loading a sound - #291

Merged
zbdd merged 2 commits into
pixijs:mainfrom
zac-vgw:fix/load-url-errors
Oct 30, 2026
Merged

zbdd merged 2 commits into
pixijs:mainfrom
zac-vgw:fix/load-url-errors

Conversation

@zac-vgw

@zac-vgw zac-vgw commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

If the fetch or response.arrayBuffer() in WebAudioMedia._loadUrl rejects, the error never reaches loaded. load() doesnt handle the returned promise, so all you get is an unhandled rejection with no URL in it.

Through Assets that means Assets.load / loadBundle never settles, and on pixi 8.19 the loader's onError and retry/skip strategies never run either.

await Assets.load('https://example.invalid/sound.mp3'); // never resolves or rejects

A 404 or 500 doesn't reject fetch, so the error body gets decoded instead. That calls loaded twice with a decode error that doesn't say which file, and with no loaded it logs nothing.

#280 is the same try/catch for v5.x. The URL and HTTP status handling here is new.

Changes

  • Fetch and arrayBuffer() failures reach loaded as Failed to load sound from <url>: <message> with the original error as cause, or go to console.error when there's no callback
  • A non-ok response is reported the same way as HTTP <status>, without reading the body
  • Decode errors reach loaded as before, without the URL
  • Through Assets.load the URL shows twice and cause is lost, since the loader builds a new error from the message

@zbdd zbdd changed the title Fix: Sound load hangs when fetch fails Fix: Report fetch and HTTP errors when loading a sound Oct 30, 2026
- Fetch and arrayBuffer() failures become "Failed to load sound from <url>: <message>" with the original error as cause
- A non-ok response is reported as "HTTP <status>" without decoding the body, which used to fail decode and call loaded twice, or log nothing with no callback
- Decode errors still reach loaded unchanged
- Tests assert after loaded settles, so a failed expect shows its diff instead of a timeout
@zbdd
zbdd force-pushed the fix/load-url-errors branch from c138a06 to 9494ee0 Compare October 30, 2026 03:58
@zbdd
zbdd merged commit 63a2318 into pixijs:main Oct 30, 2026
1 check passed
zbdd added a commit that referenced this pull request Nov 21, 2026
Backport of #291

(cherry picked from commit 63a2318)

- Cause: #280 already sent fetch and `arrayBuffer()` failures to
  `loaded` once on v5.x, but a non-ok response was still decoded, so a
  404 failed with a vague decode error. No error named the URL.
- Fix: Take main's `_loadUrl`/`_fetch` split, with `settings.ADAPTER`
  in place of `DOMAdapter.get()`. Fetch and `arrayBuffer()` failures
  become "Failed to load sound from <url>: <message>" with the original
  error as `cause`. A non-ok response is reported as "HTTP <status>"
  without decoding the body. Decode errors still reach `loaded`
  unchanged.
- Tests: Replace #280's four load-error tests in
  `test/webaudio.test.ts` with #291's five, using `settings.ADAPTER`.
  The dropped "decode throws" case is covered by the new "decode error
  unchanged" test, which also checks the error is passed through as is.

Co-authored-by: Zac Durber <109934035+zac-vgw@users.noreply.github.com>
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