Expand description
CLI error handling with semantic exit codes.
This module provides categorized errors that map to specific exit codes, enabling reliable error handling in shell scripts and CI pipelines.
§Exit Code Categories
Exit codes follow a semantic scheme where the code indicates the type of failure:
| Code | Category | Description |
|---|---|---|
| 0 | Success | Command completed successfully |
| 1 | Internal | Unexpected/internal error |
| 2 | Usage | Invalid arguments or configuration |
| 3 | NotFound | Requested resource not found |
| 4 | InvalidQuery | Query syntax or semantic error |
| 5 | Network | Network or fetch failure |
| 6 | Timeout | Operation timed out |
| 7 | Integrity | Index or data corruption |
§Usage
# Check for specific error types
blz search "query" --source missing
case $? in
0) echo "Success" ;;
3) echo "Source not found" ;;
*) echo "Other error" ;;
esac§Design
The error system is designed to:
- Provide meaningful exit codes for automation
- Preserve error context and chains (via
anyhow) - Support both machine-readable codes and human-readable messages
- Be backward compatible (errors still work as regular
anyhow::Error)
Structs§
- CliError
- A CLI error with a semantic category for exit code mapping.
Enums§
- Error
Category - Semantic error category determining the exit code.
Traits§
- Into
CliError - Extension trait for converting errors to
CliErrorwith category inference.
Functions§
- exit_
code_ from_ error - Determine the exit code from an
anyhow::Error.