Skip to main content

Module error

Module error 

Source
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:

CodeCategoryDescription
0SuccessCommand completed successfully
1InternalUnexpected/internal error
2UsageInvalid arguments or configuration
3NotFoundRequested resource not found
4InvalidQueryQuery syntax or semantic error
5NetworkNetwork or fetch failure
6TimeoutOperation timed out
7IntegrityIndex 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§

ErrorCategory
Semantic error category determining the exit code.

Traits§

IntoCliError
Extension trait for converting errors to CliError with category inference.

Functions§

exit_code_from_error
Determine the exit code from an anyhow::Error.