fix(cli): replace process::exit with ExitCode returns#186
Merged
rocketman-code merged 2 commits intomainfrom Mar 9, 2026
Merged
fix(cli): replace process::exit with ExitCode returns#186rocketman-code merged 2 commits intomainfrom
rocketman-code merged 2 commits intomainfrom
Conversation
f020df6 to
f4da2cc
Compare
process::exit bypasses Drop, which skips joining the cache-write background thread and can corrupt .chainsaw.cache. Replace all three process::exit(1) calls in main.rs with ExitCode-based control flow: - main() returns ExitCode instead of calling process::exit - run() returns Result<ExitCode, Error> for typed exit codes - --chain/--cut "no results" paths return Ok(ExitCode::FAILURE) Adds a structural regression test that scans production code for any process::exit calls, preventing reintroduction. Fixes #148
The parenthetical "(except at the CLI boundary in main.rs)" contradicted the structural test no_process_exit_in_production_code in main.rs. process::exit bypasses Drop and can corrupt the cache, so there should be no exception. Align the standard with the test.
6bbbe0d to
31dc145
Compare
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.
Summary
process::exit(1)calls inmain.rswithExitCode-based control flowmain()returnsExitCodeinstead of callingprocess::exit, ensuring all destructors runrun_trace()returnsResult<ExitCode, Error>so--chain/--cut"no results" paths useOk(ExitCode::FAILURE)instead ofprocess::exit(1)process::exitcallsWhy
process::exitbypassesDrop, which skips joining the cache-write background thread (CacheWriteHandle). This can corrupt.chainsaw.cacheand force a full rebuild on the next run. The original issue (#148) reported--max-weighterrors printing twice due toeprintln+process::exitcompeting withmain()'s error handler -- that specific instance was already fixed, but two otherprocess::exitcalls remained in the--chainand--cutpaths with the same category of bug (bypassing cleanup).Fixes #148
Test plan
cargo test --workspace-- 275 tests pass (274 existing + 1 new structural test)cargo clippy --workspace --all-targets -- -D warnings-- cleancargo fmt --check-- cleanxtask check)