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:

PatternByteMeaning
Exit::Success0OK
Cause::Fail(_)1expected typed failure
Cause::Die(_)101defect (a panic or die)
Cause::Interrupt(_)130interruption (the convention many shells use for SIGINT)
Cause::Both / Cause::Thenmax(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:

Outcomestderrexit code
success–0
typed failure Fail(e)error: {e:?}1
defect Dieerror: defect: …101
interrupterror: 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 1 for “the command could not complete successfully” (missing flag, validation error, upstream HTTP 4xx mapped to your E, …).
  • Reserve 101 for “the program detected an internal defect” — a Cause::Die (a die(..) or a panic inside an effect, which the runtime catches).
  • 130 appears 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.