Skip to content

Replace std::process::exit with ExitCode enum implementing Termination#600

Merged
sourcefrog merged 11 commits intomainfrom
copilot/remove-sys-exit-usage
Feb 8, 2026
Merged

Replace std::process::exit with ExitCode enum implementing Termination#600
sourcefrog merged 11 commits intomainfrom
copilot/remove-sys-exit-usage

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

The code was calling std::process::exit() directly, preventing proper resource cleanup and using non-idiomatic patterns for setting exit codes.

Changes

Exit code enum with Termination trait

  • Created ExitCode enum with #[repr(i32)] and explicit discriminants (0, 1, 2, 3, 4, 5, 6, 70)
  • Implemented Termination trait allowing direct return from main
  • Implemented From<ExitCode> for std::process::ExitCode

Main function signature

  • Changed from fn main() -> Result<()> to fn main() -> Result<ExitCode>
  • Removed all std::process::exit() calls throughout codebase
  • Eliminated .into() conversions (handled by Termination trait)

Return type updates

  • LabOutcome::exit_code() and DiffFilterError::exit_code() now return ExitCode enum
  • Consistent imports: use crate::exit_code::ExitCode across all files

Before:

fn main() -> Result<()> {
    // ...
    std::process::exit(lab_outcome.exit_code());
}

After:

fn main() -> Result<ExitCode> {
    // ...
    Ok(lab_outcome.exit_code())
}

Additional improvements

  • Added error logging before returning Usage exit code for invalid manifest paths
  • Added test coverage for exit codes 5 (FILTER_DIFF_MISMATCH) and 6 (FILTER_DIFF_INVALID)
  • Formatted code with cargo fmt
Original prompt

Don't use sys::exit to set the return code. Instead, return an integer (or maybe Result of an integer) from main.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits February 5, 2026 18:40
…exit

Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove sys::exit for return code in main Return ExitCode from main instead of calling std::process::exit Feb 5, 2026
Copilot AI requested a review from sourcefrog February 5, 2026 18:47
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Copilot AI changed the title Return ExitCode from main instead of calling std::process::exit Return ExitCode enum from main instead of calling std::process::exit Feb 8, 2026
Copilot AI requested a review from sourcefrog February 8, 2026 16:13
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
…tcome.rs

Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Copilot AI changed the title Return ExitCode enum from main instead of calling std::process::exit Replace std::process::exit with ExitCode enum and Termination trait Feb 8, 2026
@sourcefrog sourcefrog marked this pull request as ready for review February 8, 2026 17:55
Co-authored-by: sourcefrog <346355+sourcefrog@users.noreply.github.com>
Copilot AI changed the title Replace std::process::exit with ExitCode enum and Termination trait Replace std::process::exit with ExitCode enum implementing Termination Feb 8, 2026
@sourcefrog sourcefrog merged commit 34ceb6a into main Feb 8, 2026
28 checks passed
@sourcefrog sourcefrog deleted the copilot/remove-sys-exit-usage branch February 8, 2026 18:43
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