Skip to content

feat(🚨): add named Skia errors and raise them from native code - #4533

Open
wcandillon wants to merge 6 commits into
mainfrom
claude/nice-pasteur-31l6xd-errors
Open

wcandillon wants to merge 6 commits into
mainfrom
claude/nice-pasteur-31l6xd-errors

Conversation

@wcandillon

Copy link
Copy Markdown
Owner

Description

Part 1 of 5 of the v3 error handling RFC: the public API reports failures the way WebGPU does. Factories throw named errors instead of returning null, promises reject instead of resolving null, a lost GPU device yields dead objects instead of throws, and failures with no caller go to an uncapturederror event.

Stack:

  1. This PR: the error classes and the native plumbing
  2. Decoding and compiling factories, hooks
  3. Promise contracts
  4. GPU factories and device loss
  5. uncapturederror on Skia.gpu

Agent-written content

  • SkiaError and its subclasses (SkiaDecodeError, SkSLCompilationError, SkiaValidationError, SkiaOutOfMemoryError, SkiaGPUUnavailableError, SkiaInternalError), plus the NotSupportedError, AbortError and NotFoundError names WebGPU uses. isSkiaError() recognizes them by name on any runtime.
  • RNJsi::NamedError, a C++ exception that becomes the JS error of its name where it crosses into JS: in every host function the NativeObject installers create, and in promises (executor, settle, reject). The JS errors are built with constructors the package registers on the React Native runtime, so instanceof holds there. A worklet runtime gets an Error with the same name and extra field.
  • The web backend throws NotSupportedError for the APIs it does not have.
  • An Errors documentation page.

No public API changes behaviour yet.

Testing: yarn tsc, yarn lint and yarn test pass. The C++ was syntax-checked against the Skia, Dawn and JSI headers (Android configuration) but not built or run on a device.


Generated by Claude Code

First step of the v3 error handling RFC: one family of named errors,
modelled on WebGPU's error types, that every public API will throw or
reject with.

- SkiaError and its subclasses (SkiaDecodeError, SkSLCompilationError,
  SkiaValidationError, SkiaOutOfMemoryError, SkiaGPUUnavailableError,
  SkiaInternalError), plus the NotSupportedError, AbortError and
  NotFoundError names WebGPU uses, and isSkiaError() to recognize them by
  name on any runtime.
- RNJsi::NamedError: a C++ exception that becomes the JS error of its name
  where it crosses into JS, in every host function the NativeObject
  installers create and in promises (executor, settle, reject). The JS
  errors are built with the constructors the package registers on the React
  Native runtime, so instanceof holds there; a worklet runtime gets an Error
  with the same name and extra field.
- The web backend throws NotSupportedError for the APIs it does not have.
- An Errors documentation page.

No public API changes its behaviour yet: the factories and promises move
to these errors in the following changes.
@wcandillon
wcandillon marked this pull request as ready for review November 26, 2026 09:21
Copilot stopped work on behalf of wcandillon due to an error November 26, 2026 09:21
isSkiaError matched on the error name alone, so a DOMException of the
same name (the AbortError of an aborted fetch) passed as a Skia error.
The errors now carry a non-enumerable __rnskiaError brand, set by the
SkiaError class and by NamedError when it builds a plain Error on a
runtime without the classes, and isSkiaError requires it.

This also removes the worklet's capture of SkiaErrorNames, which was
declared after isSkiaError and read before its initialization.
…g surface

The web renderer and the shared WebGL context threw plain Errors when the
browser refused a WebGL, graphics or 2D context, so apps had to match the
message to show an empty state. They now throw SkiaSurfaceUnavailableError,
whose context field says which one failed (webgl, graphics or 2d).

This branch has not been deployed

No deployments
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