Skip to content

feat(🚨): throw named errors from the decoding and compiling factories - #4534

Open
wcandillon wants to merge 5 commits into
mainfrom
claude/nice-pasteur-31l6xd-decode
Open

wcandillon wants to merge 5 commits into
mainfrom
claude/nice-pasteur-31l6xd-decode

Conversation

@wcandillon

Copy link
Copy Markdown
Owner

Description

Part 2 of 5 of the v3 error handling RFC, stacked on part 1. The factories that decode, parse or compile no longer return null (or undefined) for a failure: they throw the named error, the same way on native and on the web.

Agent-written content

  • SkiaDecodeError (with its format) from Image.MakeFromEncoded, AnimatedImage.MakeFromEncoded, SVG.MakeFromData/MakeFromString, Typeface.MakeFromData, Skottie.Make, Picture.Make and Path.MakeFromSVGString.
  • SkSLCompilationError from RuntimeEffect.Make, whose messages give the line and position of each error. They are read from Skia's error text (SkSLErrorText, with a host-side C++ test). The web now reports them too.
  • TypeError naming the command from Path.MakeFromCmds, which used to log and return null.
  • SkiaValidationError from Image.MakeRaster and from the path effects that cannot be made (MakeDash, MakeDiscrete, MakeLine2D, MakePath1D, MakePath2D).
  • MakeCorner(r <= 0) keeps returning null to mean no effect, and <CornerPathEffect r={0} /> now draws the path as is instead of throwing.
  • Picture.Make also takes an SkData, and no longer makes an empty picture from null: Picture.MakeEmpty() does that. picture.serialize() never returns null.
  • The loading hooks keep returning null and pass the factory's error to onError; there is no more generic "Could not load data". useFonts gets onError(error, familyName) and useImageAsTexture gets onError.
  • Migration guide ("5. Handle errors"), and docs no longer use ! after these factories.

Testing: yarn tsc, yarn lint, yarn test and the cpp-tests pass. A new on-device e2e spec (DecodeErrors.spec.tsx) covers the native errors. It has not been 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.
The factories that decode, parse or compile no longer return null (or
undefined) for a failure: they throw the named error, the same on native
and on the web.

- SkiaDecodeError (with its format) from Image.MakeFromEncoded,
  AnimatedImage.MakeFromEncoded, SVG.MakeFromData/MakeFromString,
  Typeface.MakeFromData, Skottie.Make, Picture.Make and
  Path.MakeFromSVGString.
- SkSLCompilationError from RuntimeEffect.Make, with messages giving the
  line and position of each error, read from Skia's error text
  (SkSLErrorText, with host-side tests). The web now reports them too.
- TypeError naming the command from Path.MakeFromCmds, which logged and
  returned null.
- SkiaValidationError from Image.MakeRaster and the path effects that
  cannot be made (MakeDash, MakeDiscrete, MakeLine2D, MakePath1D,
  MakePath2D). MakeCorner(r <= 0) keeps returning null, as no effect, and
  <CornerPathEffect r={0} /> now draws the path as is instead of throwing.
- Picture.Make takes an SkData too and no longer makes an empty picture of
  null: Picture.MakeEmpty() does. picture.serialize() never returns null.

The loading hooks keep returning null and pass the factory's error to
onError: loadData no longer turns a null into a generic "Could not load
data". useFonts takes an onError(error, familyName) for each font that
does not load, and useImageAsTexture an onError.
@wcandillon
wcandillon changed the base branch from claude/nice-pasteur-31l6xd-errors to main November 26, 2026 15:06
…1l6xd-decode

# Conflicts:
#	apps/docs/docs/errors.md
#	packages/skia/cpp/jsi/NamedError.h
#	packages/skia/src/skia/__tests__/Errors.spec.ts
#	packages/skia/src/skia/types/Errors.ts
@wcandillon
wcandillon marked this pull request as ready for review November 26, 2026 15:15

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