Skip to content

feat: deterministic exit codes per error category#91

Merged
alvinreal merged 1 commit intomainfrom
fix/issue-85
Feb 24, 2026
Merged

feat: deterministic exit codes per error category#91
alvinreal merged 1 commit intomainfrom
fix/issue-85

Conversation

@alvinreal
Copy link
Copy Markdown
Owner

Summary

Implements deterministic, user-facing exit codes so callers can programmatically distinguish failure modes. Previously all errors exited with code 1.

Exit Code Table

Code Category Description
0 Success No error
1 General / unknown Catch-all (should not normally occur)
2 CLI / usage Invalid arguments, unknown flags
3 I/O File not found, permission denied, etc.
4 Format / parse Malformed input data
5 Mapping Error in mapping evaluation
6 Value Type mismatch, overflow, invalid cast

Changes

  • src/error.rs: Added exit_code module with named constants and MorphError::exit_code() method that maps each error variant to its code
  • src/main.rs: Updated to use e.exit_code() instead of hardcoded process::exit(1)
  • tests/exit_codes.rs: Integration tests verifying each exit code via the CLI binary (success, CLI errors, I/O errors, format errors, mapping errors, determinism)
  • Unit tests for exit code correctness, uniqueness, and non-zero guarantees

Fixes #85

Adds stable, scriptable exit codes so callers can programmatically
distinguish failure modes:

  0 - Success
  1 - General / unknown (catch-all)
  2 - CLI / usage error (invalid args, unknown format)
  3 - I/O error (file not found, permission denied)
  4 - Format / parse error (malformed input data)
  5 - Mapping error (evaluation failure)
  6 - Value error (type mismatch, overflow)

Changes:
- Add exit_code module with named constants to error.rs
- Add MorphError::exit_code() method mapping each variant to its code
- Update main.rs to use e.exit_code() instead of hardcoded 1
- Add unit tests for exit code correctness and uniqueness
- Add integration tests (tests/exit_codes.rs) verifying each code
  via the CLI binary

Fixes #85
@alvinreal alvinreal merged commit 4fea628 into main Feb 24, 2026
14 checks passed
@alvinreal alvinreal deleted the fix/issue-85 branch February 24, 2026 01:39
@github-actions github-actions bot mentioned this pull request Mar 20, 2026
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.

Stability Hardening: error taxonomy + deterministic exit codes

1 participant