Skip to main content

clawless_cli/
error.rs

1//! Error types and result aliases for Clawless commands
2//!
3//! This module re-exports [`anyhow`] error handling primitives and defines the [`CommandResult`]
4//! type alias used as the standard return type for command functions.
5
6/// Trait for adding context to errors
7///
8/// This is a re-export of `anyhow::Context` that provides the `.context()` method
9/// for adding contextual information to errors. It's renamed to avoid conflicts
10/// with a future `clawless::Context` type for application state.
11///
12/// # Example
13///
14/// ```rust,ignore
15/// use clawless::ErrorContext;
16///
17/// let result = some_operation()
18///     .context("Failed to perform operation")?;
19/// ```
20pub use anyhow::Context as ErrorContext;
21pub use anyhow::Error;
22
23/// Result type for Clawless commands
24///
25/// Commands in Clawless execute a piece of logic that might fail for various
26/// reasons. If such an error is unrecoverable during the execution of the
27/// command, it will cause the CLI to fail and exit with an error message.
28///
29/// To make it easier to handle errors when implementing commands, every command
30/// handler returns a `CommandResult` type. This makes it possible to use the
31/// question mark `?` operator and return early when an unrecoverable error
32/// occurs.
33///
34/// The `CommandResult` is a type alias for `anyhow::Result<()>`, which provides
35/// a more ergonomic way to handle arbitrary errors. Since it isn't possible to
36/// recover from the error, we do not need to provide a specific error type
37/// that a caller could handle gracefully. Similarly, commands do not need to
38/// return a value, thus the result is always `Result<()>`.
39pub type CommandResult = anyhow::Result<()>;