Skip to content

fix(cli): replace process::exit with ExitCode returns#186

Merged
rocketman-code merged 2 commits intomainfrom
fix/issue-148
Mar 9, 2026
Merged

fix(cli): replace process::exit with ExitCode returns#186
rocketman-code merged 2 commits intomainfrom
fix/issue-148

Conversation

@rocketman-code
Copy link
Owner

Summary

  • Replace all process::exit(1) calls in main.rs with ExitCode-based control flow
  • main() returns ExitCode instead of calling process::exit, ensuring all destructors run
  • run_trace() returns Result<ExitCode, Error> so --chain/--cut "no results" paths use Ok(ExitCode::FAILURE) instead of process::exit(1)
  • Adds structural regression test that scans production code for process::exit calls

Why

process::exit bypasses Drop, which skips joining the cache-write background thread (CacheWriteHandle). This can corrupt .chainsaw.cache and force a full rebuild on the next run. The original issue (#148) reported --max-weight errors printing twice due to eprintln + process::exit competing with main()'s error handler -- that specific instance was already fixed, but two other process::exit calls remained in the --chain and --cut paths 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 -- clean
  • cargo fmt --check -- clean
  • Pre-commit hook passes (runs xtask check)

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.
@rocketman-code rocketman-code merged commit 4167e28 into main Mar 9, 2026
8 checks passed
@rocketman-code rocketman-code deleted the fix/issue-148 branch March 9, 2026 03:22
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.

bug(cli): --max-weight threshold error prints twice

1 participant