Repository navigation
Define each CLI exit code in one place, with its documentation - #1255
Open
dfrankland wants to merge 2 commits into
Conversation
…tion Add `ExitCode` (cli/src/exit_code.rs) with a variant per code and a doc comment on each saying when it's used, plus `PassedThrough(code)` for the test command's code and --test-process-exit-code. Two exit codes are equal when the process exits with the same number. Every exit code decision and every field that holds one now uses it: quarantining, ErrorKind and ErrorReport, UploadReport (including cli_exit_code()), ValidateReport, ErrorSummary, the test command, main.rs and shutdown.rs. It serializes as a plain number, so the JSON doesn't change. The doc comments generate the user-facing docs: - an "Exit codes" section in --help (via clap's after_long_help), on the top-level command and each subcommand; - the ExitCode description in summary-output-schema. Remove EXIT_SUCCESS and EXIT_FAILURE from constants and drop the exitcode dependency. No behavior change: the tests only change how they build their inputs and name their expected codes; the expected numbers and text are the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dylan/trunk-22403-add-summary-output-file-to-upload-and-test #1255 +/- ##
================================================================================================
+ Coverage 84.92% 85.00% +0.07%
================================================================================================
Files 80 81 +1
Lines 18185 18295 +110
================================================================================================
+ Hits 15444 15552 +108
- Misses 2741 2743 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
strum's EnumMessage derive exposes each variant's doc comment through get_documentation(), and EnumIter lists the variants, so ExitCode no longer needs macro_rules! to keep its doc comments as strings. The numbers move into a plain match in code(). --help and summary-output-schema print exactly the same text as before. strum 0.27.2 was already in Cargo.lock through other dependencies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Stacked on #1246. Refs TRUNK-22762.
Each exit code the CLI can return is now defined once, in
cli/src/exit_code.rs, with a doc comment saying when it's used.--helpand the summary's JSON Schema are generated from those doc comments. No behavior change.What changes.
ExitCodehas a variant per code:Success(0),Failure(1),PassedThrough(code)(the test command's code, or--test-process-exit-code),Error(70),Interrupted(130),Terminated(143), andUsage(2) andPanic(101), which clap and Rust choose but users still see. strum'sEnumMessagederive reads each variant's doc comment at runtime (get_documentation()), andEnumIterlists the variants. strum 0.27.2 was already inCargo.lockthrough other dependencies.ErrorKindandErrorReport,UploadReport(includingcli_exit_code()),ValidateReport,ErrorSummary, the test command,main.rs(close_out_and_exittakes anExitCode) andshutdown.rs.TestRunResult.exit_codestays ani32, because it's the child process's raw status.PassedThrough(1) == Failure.ExitCodeserializes as a plain number, so the JSON doesn't change. ItsJsonSchemaimpl givessummary-output-schemaanExitCodedefinition whose description lists every code, generated from the doc comments.--helpon the top-level command and each subcommand ends with an "Exit codes" section (clap'safter_long_help), laid out and styled like clap's own sections.-his unchanged.EXIT_SUCCESSandEXIT_FAILUREare gone fromconstants, and so is theexitcodedependency.Documented, not in the issue's table.
uploadalso exits 0 with failed tests when quarantining is turned off for the repo in Trunk (the quarantining test intests/upload.rschecks this), or when no test reports were found.testpasses its command's code through when the upload fails, but errors before the upload (e.g. the repo root isn't a git repository) still exit 70.Out of scope. The two fail-open bugs (#1250, #1251), JSON output (TRUNK-22405) and the summary on stdout (TRUNK-22404).
Testing.
quarantine_context.exit_code = 1becomesExitCode::Failure,Some(70)becomesSome(ExitCode::Error), andexitcode::USAGEbecomesExitCode::PassedThrough(64). The expected numbers and text don't change.--helpand the schema description list every code.cargo test -p trunk-analytics-cli -p test_report -p constants: all pass except the three Swift xunit tests intests/upload.rs, which fail the same way on the base branch locally.cargo clippy -p trunk-analytics-cli --tests: no new warnings.cargo fmt --all --check: clean.🤖 Generated with Claude Code