Overview
React Native ExecuTorch provides a structured error system with typed error codes and detailed error messages. All errors are thrown asRnExecutorchError instances with specific error codes from the RnExecutorchErrorCode enum.
RnExecutorchError Class
The custom error class that all library errors use:~/workspace/source/packages/react-native-executorch/src/errors/errorUtils.ts:6-34
Basic Error Handling
Error Code Categories
Error codes are organized into categories:Application-Level Errors (100-199)
Errors from React Native ExecuTorch library code.ExecuTorch Runtime Errors (0-99)
Errors from the underlying ExecuTorch C++ runtime.Resource Fetcher Errors (180-186)
Errors related to downloading and fetching resources.Complete Error Code Reference
Application Errors
UnknownError (101)
Umbrella error for unexpected failures or 3rd-party library errors.- Unexpected exceptions from native code
- 3rd-party library errors
- Unhandled edge cases
ModuleNotLoaded (102)
Thrown when trying to run inference on an unloaded model.- Calling
forward()beforeload() - Calling
generateFromFrame()before loading - Using model after
delete()was called
FileWriteFailed (103)
Error saving output files (e.g., generated images).- Insufficient storage space
- Permission denied to write
- Invalid output path
ModelGenerating (104)
Thrown when starting inference while another is in progress.- Calling
generate()while previous generation is ongoing - Concurrent inference attempts (not supported)
LanguageNotSupported (105)
Language not supported by multilingual model (OCR, STT).InvalidConfig (112)
Invalid configuration parameters.- LLM
topPoutside [0, 1] range - Invalid temperature values
- Incorrect parameter types
InvalidModelSource (255)
Invalid type for model source.- Wrong type for ResourceSource (expected string, got object, etc.)
UnexpectedNumInputs (97)
Number of inputs doesn’t match model metadata.ThreadPoolError (113)
ExecuTorch threadpool problem.FileReadFailed (114)
Failed to read input file.- Invalid image URL
- Unsupported image format
- File doesn’t exist
- Permission denied
InvalidModelOutput (115)
Model output size is unexpected.WrongDimensions (116)
Input tensor dimensions don’t match model expectations.InvalidUserInput (117)
Invalid input to API methods.- Empty message array to LLM
generate() - Null or undefined required parameters
DownloadInterrupted (118)
Download was cancelled or paused.- User cancelled download
pauseFetching()orcancelFetching()was called- Network interrupted download
PlatformNotSupported (119)
Feature not supported on current platform.TokenizerError (167)
Tokenizer or tokenization process error.MultilingualConfiguration (160)
Mismatch between multilingual and language settings (STT).MissingDataChunk (161)
Streaming transcription attempted without audio data.StreamingNotStarted (162)
Trying to stop/insert data into non-started stream.StreamingInProgress (163)
Starting new stream while another is active.Resource Fetcher Errors
ResourceFetcherDownloadFailed (180)
Resource download failed.- Invalid URL
- Network error
- 404 Not Found
- Timeout
ResourceFetcherDownloadInProgress (181)
Attempting to start download that’s already in progress.ResourceFetcherAlreadyPaused (182)
Trying to pause already-paused download.ResourceFetcherAlreadyOngoing (183)
Trying to resume already-ongoing download.ResourceFetcherNotActive (184)
Trying to pause/resume/cancel inactive download.ResourceFetcherMissingUri (185)
Required URI information missing for download.ResourceFetcherAdapterNotInitialized (186)
Attempting to load resources without initialization.- Calling
ResourceFetcher.fetch()beforeinitExecutorch() - Using hooks before initialization
~/workspace/source/packages/react-native-executorch/src/utils/ResourceFetcher.ts:87-95
ExecuTorch Runtime Errors
These come from the underlying C++ ExecuTorch runtime:Ok (0)
Successful operation (not an error).Internal (1)
Internal ExecuTorch error.InvalidState (2)
Executor in invalid state for operation.EndOfMethod (3)
No more execution steps to run.NotSupported (16)
Operation not supported in current context.NotImplemented (17)
Operation not yet implemented.InvalidArgument (18)
Invalid argument provided.InvalidType (19)
Object has invalid type for operation.OperatorMissing (20)
Operator(s) missing in operator registry.- Model uses operators not included in build
- Custom operators not registered
NotFound (32)
Requested resource not found.MemoryAllocationFailed (33)
Could not allocate requested memory.- Insufficient device memory
- Large model on low-memory device
- Memory fragmentation
AccessFailed (34)
Could not access resource.InvalidProgram (35)
Error in program contents.- Corrupted
.ptefile - Wrong model format
- Incompatible ExecuTorch version
InvalidExternalData (36)
Error in external data contents.OutOfResources (37)
Not enough resources for operation.DelegateInvalidCompatibility (48)
Backend received incompatible delegate version.DelegateMemoryAllocationFailed (49)
Backend failed to allocate memory.DelegateInvalidHandle (50)
Invalid delegate handle. Location:~/workspace/source/packages/react-native-executorch/src/errors/ErrorCodes.ts:4-185
Error Parsing
TheparseUnknownError utility converts unknown errors to RnExecutorchError:
~/workspace/source/packages/react-native-executorch/src/errors/errorUtils.ts:49-66
Best Practices
1. Always Use Try-Catch
2. Check Error Codes
3. Provide User Feedback
4. Log for Debugging
5. Implement Retry Logic
6. Clean Up on Error
Complete Error Handling Example
Next Steps
- Architecture - Understand the overall system architecture
- Resource Fetching - Learn about download error handling
- Model Loading - See how errors occur during loading