Skip to content

refactor: use exitCodes enum everywhere#1570

Merged
jonahsnider merged 2 commits into
mainfrom
refactor/exit-code-enum
Jul 22, 2026
Merged

refactor: use exitCodes enum everywhere#1570
jonahsnider merged 2 commits into
mainfrom
refactor/exit-code-enum

Conversation

@jonahsnider

@jonahsnider jonahsnider commented Jul 21, 2026

Copy link
Copy Markdown
Member

Instead of using a mix of the exitCodes enum and hardcoded constants, standardize on using the enum for everything. Was brought up in #1500 during review.


Note

Low Risk
Mechanical refactor with identical exit code values; low risk aside from tests that may still assert {exit: 1} instead of exitCodes.RUNTIME_ERROR.

Overview
Standardizes CLI exit handling by replacing literal 0, 1, 2, and 130 with the shared exitCodes constants from @sanity/cli-core across command implementations.

this.error(), this.output.error(), this.exit(), and process.exit() now reference names like exitCodes.RUNTIME_ERROR, exitCodes.USAGE_ERROR, and exitCodes.SIGINT instead of magic numbers. CONTRIBUTING.md and the command examples are updated to document and demonstrate the same pattern.

Exit semantics are unchanged (still 0/1/2/3/130); this is naming and consistency only, with broader import of exitCodes where it was missing.

Reviewed by Cursor Bugbot for commit 9372603. Bugbot is set up for automated code reviews on this repo. Configure here.

@jonahsnider
jonahsnider requested a review from a team as a code owner July 21, 2026 01:15
@jonahsnider
jonahsnider enabled auto-merge (squash) July 21, 2026 01:15
@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

📦 Bundle Stats — @sanity/cli

Compared against main (cd5754f7)

@sanity/cli

Metric Value vs main (cd5754f)
Internal (raw) 2.2 KB -
Internal (gzip) 838 B -
Bundled (raw) 11.20 MB -
Bundled (gzip) 2.11 MB -
Import time 860ms -2ms, -0.3%

bin:sanity

Metric Value vs main (cd5754f)
Internal (raw) 782 B -
Internal (gzip) 423 B -
Bundled (raw) 9.90 MB -
Bundled (gzip) 1.78 MB -
Import time 2.07s +11ms, +0.5%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — @sanity/cli-core

Compared against main (cd5754f7)

Metric Value vs main (cd5754f)
Internal (raw) 114.1 KB -
Internal (gzip) 29.2 KB -
Bundled (raw) 21.76 MB -
Bundled (gzip) 3.46 MB -
Import time 766ms +3ms, +0.4%

🗺️ View treemap · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — @sanity/cli-build

Compared against main (cd5754f7)

@sanity/cli-build/_internal/build

Metric Value vs main (cd5754f)
Internal (raw) 113.8 KB -
Internal (gzip) 28.7 KB -
Bundled (raw) 17.76 MB +720 B, +0.0%
Bundled (gzip) 3.56 MB +239 B, +0.0%
Import time 1.11s -4ms, -0.4%

@sanity/cli-build/_internal/env

Metric Value vs main (cd5754f)
Internal (raw) 1.8 KB -
Internal (gzip) 644 B -
Bundled (raw) 1.31 MB -
Bundled (gzip) 333.8 KB -
Import time 122ms +0ms, +0.3%

@sanity/cli-build/_internal/extract

Metric Value vs main (cd5754f)
Internal (raw) 8.6 KB -
Internal (gzip) 2.7 KB -
Bundled (raw) 155.0 KB -
Bundled (gzip) 39.5 KB -
Import time 239ms -3ms, -1.2%

🗺️ ./_internal/env · ./_internal/extract · @sanity/cli-build:./_internal/build treemap too large to embed · Artifacts

Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

📦 Bundle Stats — create-sanity

Compared against main (cd5754f7)

Metric Value vs main (cd5754f)
Internal (raw) 908 B -
Internal (gzip) 483 B -
Bundled (raw) 931 B -
Bundled (gzip) 491 B -
Import time ❌ ChildProcess denied: node -
Details
  • Import time regressions over 10% are flagged with ⚠️
  • Sizes shown as raw / gzip 🗜️. Internal bytes = own code only. Total bytes = with all dependencies. Import time = Node.js cold-start median.

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Coverage Delta

File Statements
packages/@sanity/cli/src/commands/backups/disable.ts 91.9% (±0%)
packages/@sanity/cli/src/commands/backups/download.ts 94.8% (±0%)
packages/@sanity/cli/src/commands/backups/enable.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/backups/list.ts 96.8% (±0%)
packages/@sanity/cli/src/commands/codemod.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/cors/add.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/cors/delete.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/cors/list.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/datasets/alias/create.ts 96.0% (±0%)
packages/@sanity/cli/src/commands/datasets/alias/delete.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/datasets/alias/link.ts 93.4% (±0%)
packages/@sanity/cli/src/commands/datasets/alias/unlink.ts 93.2% (±0%)
packages/@sanity/cli/src/commands/datasets/copy.ts 91.4% (±0%)
packages/@sanity/cli/src/commands/datasets/create.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/datasets/delete.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/datasets/embeddings/disable.ts 83.3% (±0%)
packages/@sanity/cli/src/commands/datasets/embeddings/enable.ts 84.7% (±0%)
packages/@sanity/cli/src/commands/datasets/embeddings/status.ts 85.2% (±0%)
packages/@sanity/cli/src/commands/datasets/export.ts 91.8% (±0%)
packages/@sanity/cli/src/commands/datasets/import.ts 87.7% (±0%)
packages/@sanity/cli/src/commands/datasets/list.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/datasets/visibility/get.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/datasets/visibility/set.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/deploy.ts 85.2% (±0%)
packages/@sanity/cli/src/commands/dev.ts 21.1% (±0%)
packages/@sanity/cli/src/commands/docs/read.ts 96.9% (±0%)
packages/@sanity/cli/src/commands/docs/search.ts 97.5% (±0%)
packages/@sanity/cli/src/commands/doctor.ts 70.6% (±0%)
packages/@sanity/cli/src/commands/documents/create.ts 93.1% (±0%)
packages/@sanity/cli/src/commands/documents/delete.ts 94.6% (±0%)
packages/@sanity/cli/src/commands/documents/get.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/documents/query.ts 96.8% (±0%)
packages/@sanity/cli/src/commands/documents/validate.ts 92.8% (±0%)
packages/@sanity/cli/src/commands/graphql/deploy.ts 41.1% (±0%)
packages/@sanity/cli/src/commands/graphql/list.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/graphql/undeploy.ts 97.7% (±0%)
packages/@sanity/cli/src/commands/hooks/attempt.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/hooks/create.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/hooks/delete.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/hooks/list.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/hooks/logs.ts 96.0% (±0%)
packages/@sanity/cli/src/commands/login.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/logout.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/mcp/configure.ts 90.0% (±0%)
packages/@sanity/cli/src/commands/media/create-aspect.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/media/delete-aspect.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/media/deploy-aspect.ts 97.0% (±0%)
packages/@sanity/cli/src/commands/media/export.ts 78.8% (±0%)
packages/@sanity/cli/src/commands/media/import.ts 91.8% (±0%)
packages/@sanity/cli/src/commands/migrations/create.ts 94.7% (±0%)
packages/@sanity/cli/src/commands/migrations/list.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/migrations/run.ts 95.1% (±0%)
packages/@sanity/cli/src/commands/openapi/get.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/openapi/list.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/organizations/create.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/organizations/delete.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/organizations/get.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/organizations/list.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/organizations/update.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/projects/create.ts 98.3% (±0%)
packages/@sanity/cli/src/commands/schemas/validate.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/skills/install.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/telemetry/disable.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/telemetry/enable.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/tokens/create.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/tokens/delete.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/tokens/list.ts 100.0% (±0%)
packages/@sanity/cli/src/commands/users/invite.ts 97.9% (±0%)

Comparing 68 changed files against main @ b00bd52f5068b4f59e52c45945d9dc0a200b9f6e

Overall Coverage

Metric Coverage
Statements 78.2% (±0%)
Branches 69.6% (±0%)
Functions 74.0% (- 0.0%)
Lines 78.6% (±0%)

Comment thread CONTRIBUTING.md
### In Practice

- For `this.output.error()`: pass `{exit: 1}` for runtime errors, `{exit: 2}` (or omit) for usage errors.
- For `this.output.error()`: pass `{exit: exitCodes.RUNTIME_ERROR}` for runtime errors, `{exit: exitCodes.USAGE_ERROR}` (or omit) for usage errors.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:chefs-kiss:

Comment thread CONTRIBUTING.md
- **0 - Success**: Command completed normally. Implicit when `run()` returns without throwing. Only use `this.exit(0)` when you need to short-circuit early on a successful path.
- **1 - Runtime error**: Something went wrong during execution that is not the user's fault. API failures, network errors, missing project config, file system errors, unexpected state. Use `this.output.error(message, {exit: 1})`.
- **2 - Usage error**: The user provided invalid input to the CLI itself. Bad arguments, unknown flags, invalid flag values, failing input validation. This is oclif's default for `this.output.error()` and all parse errors, so omitting the `exit` option also gives you 2. Use `this.output.error(message, {exit: 2})` or `this.output.error(message)`.
- **0 - Success**: Command completed normally. Implicit when `run()` returns without throwing. Only use `this.exit(exitCodes.SUCCESS)` when you need to short-circuit early on a successful path.

@shapirodaniel shapirodaniel Jul 22, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huge win for future agentic work! thanks for including these docs ❤️

@shapirodaniel shapirodaniel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome!

@jonahsnider
jonahsnider merged commit d2200e3 into main Jul 22, 2026
57 checks passed
@jonahsnider
jonahsnider deleted the refactor/exit-code-enum branch July 22, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants