Skip to main content

classify_error

Function classify_error 

Source
pub fn classify_error(err: &Error) -> CliExitCode
Expand description

Classify an error into appropriate exit code category

Examines the error message and context chain to determine the most appropriate exit code per M2_CLI_SPEC.md exit code policy.

Classification logic (order matters - most specific first):

  1. CLI argument parsing errors -> InvalidCliArgs (2)
  2. Schema-related errors -> SchemaError (3)
  3. Data directory/SSTable errors -> DataDirError (4)
  4. Default: Query execution errors -> QueryExecutionError (5)

§Examples

use anyhow::anyhow;
use cqlite_cli::error::{classify_error, CliExitCode};

let err = anyhow!("Failed to parse schema file");
assert_eq!(classify_error(&err), CliExitCode::SchemaError);

let err = anyhow!("Data directory not found");
assert_eq!(classify_error(&err), CliExitCode::DataDirError);