Problem description
scripts/generate-errors.ts (run via yarn codegen:errors) is the single source of truth for error codes. It reads scripts/errors.config.ts and writes two generated files:
packages/react-native-executorch/src/errors/ErrorCodes.ts
packages/react-native-executorch/common/rnexecutorch/ErrorCodes.h
.github/workflows/ci.yml runs only lint, typecheck, and build-library. Nothing verifies that the committed generated files actually match errors.config.ts. A contributor who edits errors.config.ts (or hand-edits a generated file) without rerunning codegen will commit sources that silently disagree.
Because the same numeric codes cross the JSI boundary, drift is not cosmetic: a code thrown from C++ can resolve to a different name — or to no enum member — on the TS side. This exact failure mode is already documented in the RnExecutorchError class doc comment in src/errors/errorUtils.ts, which notes codes "flow through as a raw number" when the generated files drift.
Proposed solution
Add a CI step (cheapest to fold into the existing lint job — no native build needed) that regenerates and diffs:
- name: Verify error codes are up to date
run: |
yarn codegen:errors
git diff --exit-code -- \
packages/react-native-executorch/src/errors/ErrorCodes.ts \
packages/react-native-executorch/common/rnexecutorch/ErrorCodes.h \
|| { echo "::error::Error codes are stale. Run 'yarn codegen:errors' and commit the result."; exit 1; }
Alternative solutions
A lefthook pre-commit hook could regenerate + stage automatically, but it's bypassable with --no-verify and does nothing for changes made via the GitHub web UI or introduced during a rebase. CI is the authoritative gate; a hook is a complementary convenience, not a replacement.
Benefits to React Native ExecuTorch
Guarantees the C++/TS error-code contract cannot silently diverge, protecting the error-handling path every module depends on. Effectively free (TS-only, no emulator/native toolchain).
Additional context
Generated outputs and their writer are at scripts/generate-errors.ts:84-117. Root script: codegen:errors in the top-level package.json.
Problem description
scripts/generate-errors.ts(run viayarn codegen:errors) is the single source of truth for error codes. It readsscripts/errors.config.tsand writes two generated files:packages/react-native-executorch/src/errors/ErrorCodes.tspackages/react-native-executorch/common/rnexecutorch/ErrorCodes.h.github/workflows/ci.ymlruns onlylint,typecheck, andbuild-library. Nothing verifies that the committed generated files actually matcherrors.config.ts. A contributor who editserrors.config.ts(or hand-edits a generated file) without rerunning codegen will commit sources that silently disagree.Because the same numeric codes cross the JSI boundary, drift is not cosmetic: a code thrown from C++ can resolve to a different name — or to no enum member — on the TS side. This exact failure mode is already documented in the
RnExecutorchErrorclass doc comment insrc/errors/errorUtils.ts, which notes codes "flow through as a raw number" when the generated files drift.Proposed solution
Add a CI step (cheapest to fold into the existing
lintjob — no native build needed) that regenerates and diffs:Alternative solutions
A
lefthookpre-commit hook could regenerate + stage automatically, but it's bypassable with--no-verifyand does nothing for changes made via the GitHub web UI or introduced during a rebase. CI is the authoritative gate; a hook is a complementary convenience, not a replacement.Benefits to React Native ExecuTorch
Guarantees the C++/TS error-code contract cannot silently diverge, protecting the error-handling path every module depends on. Effectively free (TS-only, no emulator/native toolchain).
Additional context
Generated outputs and their writer are at
scripts/generate-errors.ts:84-117. Root script:codegen:errorsin the top-levelpackage.json.