Skip to content

[CI] Verify generated error codes stay in sync with errors.config.ts #1209

@msluszniak

Description

@msluszniak

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.

Metadata

Metadata

Assignees

Labels

Coredev expThis issue tackles problems with developer experience e.g. debbugingtestIssue and PR related to tests or testing infrastructure

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions