Exit codes for main
When a CLI finishes, the OS only sees an 8-bit exit status. id_effect distinguishes richer outcomes (Exit, Cause); at the process edge you collapse that into std::process::ExitCode.
The Exit / Cause mapping
Running an effect at the edge (block_on, or id_effect_cli::run_main) gives you its full Exit. Leaf causes map as follows; composite Cause::Both / Cause::Then use the maximum byte so “stronger” failures dominate:
| Pattern | Byte | Meaning |
|---|---|---|
Exit::Success | 0 | OK |
Cause::Fail(_) | 1 | expected typed failure |
Cause::Die(_) | 101 | defect (a panic or die) |
Cause::Interrupt(_) | 130 | interruption (the convention many shells use for SIGINT) |
Cause::Both / Cause::Then | max(left, right) | recurse |
Helpers: exit_code_for_exit, exit_code_for_cause, cause_max_exit_byte. For a plain Result (Ok → 0, Err → 1) there is exit_code_for_result.
What run_main prints
run_main maps the whole Exit with the table above and reports a failure on stderr:
| Outcome | stderr | exit code |
|---|---|---|
| success | – | 0 |
typed failure Fail(e) | error: {e:?} | 1 |
defect Die | error: defect: … | 101 |
| interrupt | error: interrupted (…) | 130 |
Typed failures are printed with Debug; for user-facing output, map your error to a String (or a thin Display wrapper) first: run_main(program.map_err(|e| e.to_string()), env, RunMainConfig::minimal()).
Practical guidance
- Use
1for “the command could not complete successfully” (missing flag, validation error, upstream HTTP 4xx mapped to yourE, …). - Reserve
101for “the program detected an internal defect” — aCause::Die(adie(..)or a panic inside an effect, which the runtime catches). 130appears when the root fiber is interrupted.
If you need richer machine output, prefer stderr JSON or a dedicated output file — do not overload exit codes beyond what your operators can act on.