refactor: use exitCodes enum everywhere#1570
Merged
Merged
Conversation
Contributor
📦 Bundle Stats —
|
| 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.
Contributor
Coverage Delta
Comparing 68 changed files against main @ Overall Coverage
|
| ### 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. |
| - **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. |
There was a problem hiding this comment.
huge win for future agentic work! thanks for including these docs ❤️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Instead of using a mix of the
exitCodesenum 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 ofexitCodes.RUNTIME_ERROR.Overview
Standardizes CLI exit handling by replacing literal
0,1,2, and130with the sharedexitCodesconstants from@sanity/cli-coreacross command implementations.this.error(),this.output.error(),this.exit(), andprocess.exit()now reference names likeexitCodes.RUNTIME_ERROR,exitCodes.USAGE_ERROR, andexitCodes.SIGINTinstead 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
exitCodeswhere it was missing.Reviewed by Cursor Bugbot for commit 9372603. Bugbot is set up for automated code reviews on this repo. Configure here.