Pcornel
Automation · Error Handling

Exit Codes

Cheat sheet · https://pcornel.dk/topic.php?topic=5973

Back to the Topic

Answer

Exit codes in error handling tell the caller whether automation succeeded: 0 for success, non-zero for distinct failures. CI pipelines and schedulers rely on them to mark jobs as failed.

Remember

  • 0 means success, non-zero means failure.
  • Use distinct codes for distinct failures.
  • CI and schedulers rely on exit codes.

First checks

  • echo $? — Bash
  • $LASTEXITCODE — PowerShell native
  • Documented exit code meanings — contract

Verify in this order

run → exit code → caller decision

Where it usually breaks

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5973

Confirmation

Confirm action

Continue?