Skip to content

Commit 65915c0

Browse files
authored
ci: verify generated error codes stay in sync with errors.config.ts (#1214)
## Description `scripts/generate-errors.ts` (`yarn codegen:errors`) is the single source of truth for error codes, emitting `src/errors/ErrorCodes.ts` and `common/rnexecutorch/ErrorCodes.h`. Nothing in CI verified the committed generated files match `errors.config.ts`, so a contributor editing the config (or a generated file) without rerunning codegen could commit sources that silently disagree across the JSI boundary. This adds a `lint`-job step that reruns codegen and diffs both generated files against what's committed, failing CI on drift. No native toolchain needed. While wiring this up, the committed `ErrorCodes.h` is now stored verbatim as the generator emits it. The `clang-format` pre-commit hook previously rewrapped its comments, which would have made the raw diff fail in CI, so the generated header is excluded from that hook. ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [x] Other (chores, tests, code style improvements etc.) ### Tested on - [ ] iOS - [ ] Android ### Testing instructions 1. Edit `scripts/errors.config.ts` (e.g. rename a code) without running codegen. 2. The new "Verify error codes are up to date" CI step fails with a stale-codes error. 3. Run `yarn codegen:errors`, commit the result — the step passes. ### Related issues Closes #1209 ### Checklist - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings
1 parent f32eca8 commit 65915c0

3 files changed

Lines changed: 33 additions & 44 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ jobs:
2626
- name: Typecheck files
2727
run: yarn workspaces foreach --all --topological-dev run prepare && yarn typecheck
2828

29+
- name: Verify error codes are up to date
30+
run: |
31+
yarn codegen:errors
32+
git diff --exit-code -- \
33+
packages/react-native-executorch/src/errors/ErrorCodes.ts \
34+
packages/react-native-executorch/common/rnexecutorch/ErrorCodes.h \
35+
|| { echo "::error::Error codes are stale. Run 'yarn codegen:errors' and commit the result."; exit 1; }
36+
2937
build-library:
3038
runs-on: ubuntu-latest
3139
steps:

‎lefthook.yml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ pre-commit:
1212
run: npx prettier --write {staged_files} && git add {staged_files}
1313
format-objc:
1414
glob: '*.{h,hpp,m,mm,c,cpp}'
15+
# ErrorCodes.h is generated verbatim by `yarn codegen:errors` and verified
16+
# in CI with a raw diff; clang-format would rewrap its comments and break
17+
# that check, so it is excluded here.
18+
exclude:
19+
- 'packages/react-native-executorch/common/rnexecutorch/ErrorCodes.h'
1520
run: clang-format -i {staged_files} && git add {staged_files}
1621
format-kotlin:
1722
glob: '*.{kt}'

‎packages/react-native-executorch/common/rnexecutorch/ErrorCodes.h‎

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,108 +9,87 @@ namespace rnexecutorch {
99

1010
enum class RnExecutorchErrorCode : int32_t {
1111
/**
12-
* An umbrella-error that is thrown usually when something unexpected happens,
13-
* for example a 3rd-party library error.
12+
* An umbrella-error that is thrown usually when something unexpected happens, for example a 3rd-party library error.
1413
*/
1514
UnknownError = 101,
1615
/**
17-
* Thrown when a user tries to run a model that is not yet downloaded or
18-
* loaded into memory.
16+
* Thrown when a user tries to run a model that is not yet downloaded or loaded into memory.
1917
*/
2018
ModuleNotLoaded = 102,
2119
/**
22-
* An error ocurred when saving a file. This could be, for instance a result
23-
* image from an image model.
20+
* An error ocurred when saving a file. This could be, for instance a result image from an image model.
2421
*/
2522
FileWriteFailed = 103,
2623
/**
27-
* Thrown when a user tries to run a model that is currently processing. It is
28-
* only allowed to run a single model prediction at a time.
24+
* Thrown when a user tries to run a model that is currently processing. It is only allowed to run a single model prediction at a time.
2925
*/
3026
ModelGenerating = 104,
3127
/**
32-
* Thrown when a language is passed to a multi-language model that is not
33-
* supported. For example OCR or Speech To Text.
28+
* Thrown when a language is passed to a multi-language model that is not supported. For example OCR or Speech To Text.
3429
*/
3530
LanguageNotSupported = 105,
3631
/**
37-
* Thrown when config parameters passed to a model are invalid. For example,
38-
* when LLM's topp is outside of range [0, 1].
32+
* Thrown when config parameters passed to a model are invalid. For example, when LLM's topp is outside of range [0, 1].
3933
*/
4034
InvalidConfig = 112,
4135
/**
4236
* Thrown when React Native ExecuTorch threadpool problem occurs.
4337
*/
4438
ThreadPoolError = 113,
4539
/**
46-
* Thrown when a file read operation failed. This could be invalid image url
47-
* passed to image models, or unsupported format.
40+
* Thrown when a file read operation failed. This could be invalid image url passed to image models, or unsupported format.
4841
*/
4942
FileReadFailed = 114,
5043
/**
51-
* Thrown when the size of model output is unexpected. If you're using your
52-
* custom model with any of the pre-defined modules, please verify docs or
53-
* source code for the expected model I/O contract.
44+
* Thrown when the size of model output is unexpected. If you're using your custom model with any of the pre-defined modules, please verify docs or source code for the expected model I/O contract.
5445
*/
5546
InvalidModelOutput = 115,
5647
/**
57-
* Thrown when the dimensions of input tensors don't match the model's
58-
* expected dimensions.
48+
* Thrown when the dimensions of input tensors don't match the model's expected dimensions.
5949
*/
6050
WrongDimensions = 116,
6151
/**
62-
* Thrown when the input passed to our APIs is invalid, for example when
63-
* passing an empty message array to LLM's generate().
52+
* Thrown when the input passed to our APIs is invalid, for example when passing an empty message array to LLM's generate().
6453
*/
6554
InvalidUserInput = 117,
6655
/**
67-
* Thrown when the number of downloaded files is unexpected, due to download
68-
* interruptions.
56+
* Thrown when the number of downloaded files is unexpected, due to download interruptions.
6957
*/
7058
DownloadInterrupted = 118,
7159
/**
72-
* Thrown when a feature or platform is not supported in the current
73-
* environment.
60+
* Thrown when a feature or platform is not supported in the current environment.
7461
*/
7562
PlatformNotSupported = 119,
7663
/**
7764
* Thrown when the type of model source passed by the user is invalid.
7865
*/
7966
InvalidModelSource = 120,
8067
/**
81-
* Thrown when the number of passed inputs to the model is different than the
82-
* model metadata specifies. If you're using your custom model with any of the
83-
* pre-defined modules, please verify docs or source code for the expected
84-
* model I/O contract.
68+
* Thrown when the number of passed inputs to the model is different than the model metadata specifies. If you're using your custom model with any of the pre-defined modules, please verify docs or source code for the expected model I/O contract.
8569
*/
8670
UnexpectedNumInputs = 121,
8771
/**
8872
* Thrown when an error occurs with the tokenizer or tokenization process.
8973
*/
9074
TokenizerError = 122,
9175
/**
92-
* Thrown when there's a configuration mismatch between multilingual and
93-
* language settings in Speech-to-Text models.
76+
* Thrown when there's a configuration mismatch between multilingual and language settings in Speech-to-Text models.
9477
*/
9578
MultilingualConfiguration = 160,
9679
/**
97-
* Thrown when streaming transcription is attempted but audio data chunk is
98-
* missing.
80+
* Thrown when streaming transcription is attempted but audio data chunk is missing.
9981
*/
10082
MissingDataChunk = 161,
10183
/**
102-
* Thrown when trying to stop or insert data into a stream that hasn't been
103-
* started.
84+
* Thrown when trying to stop or insert data into a stream that hasn't been started.
10485
*/
10586
StreamingNotStarted = 162,
10687
/**
107-
* Thrown when trying to start a new streaming session while another is
108-
* already in progress.
88+
* Thrown when trying to start a new streaming session while another is already in progress.
10989
*/
11090
StreamingInProgress = 163,
11191
/**
112-
* Thrown when a resource fails to download. This could be due to invalid URL,
113-
* or for example a network problem.
92+
* Thrown when a resource fails to download. This could be due to invalid URL, or for example a network problem.
11493
*/
11594
ResourceFetcherDownloadFailed = 180,
11695
/**
@@ -126,8 +105,7 @@ enum class RnExecutorchErrorCode : int32_t {
126105
*/
127106
ResourceFetcherAlreadyOngoing = 183,
128107
/**
129-
* Thrown when trying to pause, resume, or cancel a download that is not
130-
* active.
108+
* Thrown when trying to pause, resume, or cancel a download that is not active.
131109
*/
132110
ResourceFetcherNotActive = 184,
133111
/**
@@ -139,9 +117,7 @@ enum class RnExecutorchErrorCode : int32_t {
139117
*/
140118
ResourceFetcherAdapterNotInitialized = 186,
141119
/**
142-
* Thrown when the platform does not support the resource fetching feature,
143-
* which is required for downloading models and other resources in React
144-
* Native ExecuTorch.
120+
* Thrown when the platform does not support the resource fetching feature, which is required for downloading models and other resources in React Native ExecuTorch.
145121
*/
146122
ResourceFetcherPlatformNotSupported = 187,
147123
};

0 commit comments

Comments
 (0)