Repository navigation
feat(🚨): throw named errors from the decoding and compiling factories - #4534
Open
wcandillon wants to merge 5 commits into
Open
wcandillon wants to merge 5 commits into
wcandillon wants to merge 5 commits into
Conversation
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.
…teur-31l6xd-decode
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
marked this pull request as ready for review
November 26, 2026 15:15
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 itsformat) fromImage.MakeFromEncoded,AnimatedImage.MakeFromEncoded,SVG.MakeFromData/MakeFromString,Typeface.MakeFromData,Skottie.Make,Picture.MakeandPath.MakeFromSVGString.SkSLCompilationErrorfromRuntimeEffect.Make, whosemessagesgive 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.TypeErrornaming the command fromPath.MakeFromCmds, which used to log and return null.SkiaValidationErrorfromImage.MakeRasterand 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.Makealso takes anSkData, and no longer makes an empty picture from null:Picture.MakeEmpty()does that.picture.serialize()never returns null.onError; there is no more generic "Could not load data".useFontsgetsonError(error, familyName)anduseImageAsTexturegetsonError.!after these factories.Testing:
yarn tsc,yarn lint,yarn testand 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