CliError

Enum CliError 

Source
pub enum CliError {
    Configuration(String),
    Validation(String),
    Execution(String),
    Git(String),
    Package(String),
    Io(String),
    Network(String),
    User(String),
}
Expand description

Main error type for CLI operations.

This enum represents all possible error conditions that can occur during CLI execution. Each variant provides context-specific information and maps to an appropriate exit code following the sysexits standard.

§Error Categories

  • Configuration: Config file issues, invalid settings
  • Validation: Invalid arguments, invalid state
  • Execution: Command failures, operation failures
  • Git: Repository errors, git operation failures
  • Package: Package.json issues, dependency problems
  • Io: File system errors, permission issues
  • Network: Registry unreachable, download failures
  • User: Invalid input, cancelled operations

§Examples

use sublime_cli_tools::error::CliError;

let error = CliError::configuration("Invalid config");
assert_eq!(error.exit_code(), 78);
assert_eq!(error.as_ref(), "CliError::Configuration");

Variants§

§

Configuration(String)

Configuration-related errors (invalid, not found, parsing failed).

Exit code: 78 (EX_CONFIG)

§Examples

  • Configuration file not found
  • Invalid configuration format
  • Configuration validation failed
§

Validation(String)

Validation errors (invalid arguments, invalid state).

Exit code: 65 (EX_DATAERR)

§Examples

  • Invalid command arguments
  • Invalid version format
  • Invalid changeset data
§

Execution(String)

Execution errors (command failed, operation failed).

Exit code: 70 (EX_SOFTWARE)

§Examples

  • Command execution failed
  • Operation could not be completed
  • Internal processing error
§

Git(String)

Git-related errors (repository not found, git operation failed).

Exit code: 70 (EX_SOFTWARE)

§Examples

  • Repository not found
  • Git command failed
  • Branch operation failed
§

Package(String)

Package-related errors (package not found, package.json invalid).

Exit code: 65 (EX_DATAERR)

§Examples

  • Package.json not found
  • Invalid package.json format
  • Dependency resolution failed
§

Io(String)

I/O errors (file not found, permission denied).

Exit code: 74 (EX_IOERR)

§Examples

  • File not found
  • Permission denied
  • Disk full
§

Network(String)

Network errors (registry unreachable, download failed).

Exit code: 69 (EX_UNAVAILABLE)

§Examples

  • npm registry unreachable
  • Download timeout
  • Network connection lost
§

User(String)

User-caused errors (invalid input, cancelled operation).

Exit code: 64 (EX_USAGE)

§Examples

  • Invalid user input
  • Operation cancelled by user
  • Interactive prompt declined

Implementations§

Source§

impl CliError

Source

pub fn configuration(msg: impl Into<String>) -> Self

Creates a new Configuration error.

§Examples
use sublime_cli_tools::error::CliError;

let error = CliError::configuration("File not found");
assert_eq!(error.exit_code(), 78);
Source

pub fn validation(msg: impl Into<String>) -> Self

Creates a new Validation error.

§Examples
use sublime_cli_tools::error::CliError;

let error = CliError::validation("Invalid version format");
assert_eq!(error.exit_code(), 65);
Source

pub fn execution(msg: impl Into<String>) -> Self

Creates a new Execution error.

§Examples
use sublime_cli_tools::error::CliError;

let error = CliError::execution("Command failed");
assert_eq!(error.exit_code(), 70);
Source

pub fn git(msg: impl Into<String>) -> Self

Creates a new Git error.

§Examples
use sublime_cli_tools::error::CliError;

let error = CliError::git("Repository not found");
assert_eq!(error.exit_code(), 70);
Source

pub fn package(msg: impl Into<String>) -> Self

Creates a new Package error.

§Examples
use sublime_cli_tools::error::CliError;

let error = CliError::package("package.json not found");
assert_eq!(error.exit_code(), 65);
Source

pub fn io(msg: impl Into<String>) -> Self

Creates a new I/O error.

§Examples
use sublime_cli_tools::error::CliError;

let error = CliError::io("Permission denied");
assert_eq!(error.exit_code(), 74);
Source

pub fn network(msg: impl Into<String>) -> Self

Creates a new Network error.

§Examples
use sublime_cli_tools::error::CliError;

let error = CliError::network("Registry unreachable");
assert_eq!(error.exit_code(), 69);
Source

pub fn user(msg: impl Into<String>) -> Self

Creates a new User error.

§Examples
use sublime_cli_tools::error::CliError;

let error = CliError::user("Operation cancelled");
assert_eq!(error.exit_code(), 64);
Source

pub fn exit_code(&self) -> i32

Returns the exit code for this error following sysexits convention.

§Exit Codes
  • Configuration: 78 (EX_CONFIG)
  • Validation: 65 (EX_DATAERR)
  • Package: 65 (EX_DATAERR)
  • Execution: 70 (EX_SOFTWARE)
  • Git: 70 (EX_SOFTWARE)
  • Io: 74 (EX_IOERR)
  • Network: 69 (EX_UNAVAILABLE)
  • User: 64 (EX_USAGE)
§Examples
use sublime_cli_tools::error::CliError;

let error = CliError::configuration("Invalid config");
assert_eq!(error.exit_code(), 78);

let error = CliError::network("Registry down");
assert_eq!(error.exit_code(), 69);
Source

pub fn user_message(&self) -> String

Returns a user-friendly error message.

This message is displayed to the user and provides clear information about what went wrong and how to fix it.

§Examples
use sublime_cli_tools::error::CliError;

let error = CliError::configuration("File not found");
let message = error.user_message();
assert!(message.contains("Configuration error"));
Source

pub fn kind(&self) -> &'static str

Returns the error category as a string identifier.

This is useful for programmatic error handling and logging.

§Examples
use sublime_cli_tools::error::CliError;

let error = CliError::configuration("Test");
assert_eq!(error.kind(), "Configuration");

let error = CliError::network("Test");
assert_eq!(error.kind(), "Network");

Trait Implementations§

Source§

impl AsRef<str> for CliError

Source§

fn as_ref(&self) -> &str

Returns a string identifier for the error type.

This is useful for error matching and categorization in logs or error reporting systems.

§Examples
use sublime_cli_tools::error::CliError;

let error = CliError::configuration("test");
assert_eq!(error.as_ref(), "CliError::Configuration");

let error = CliError::git("test");
assert_eq!(error.as_ref(), "CliError::Git");
Source§

impl Debug for CliError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for CliError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for CliError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<Error> for CliError

Source§

fn from(error: Error) -> Self

Converts a package tools error to a CLI error.

Maps package tool errors to appropriate CLI error categories.

Source§

impl From<Error> for CliError

Source§

fn from(error: Error) -> Self

Converts a standard tools error to a CLI error.

Maps standard tool errors to appropriate CLI error categories.

Source§

impl From<Error> for CliError

Source§

fn from(error: Error) -> Self

Converts a standard I/O error to a CLI error.

§Examples
use sublime_cli_tools::error::CliError;
use std::io;

let io_error = io::Error::new(io::ErrorKind::NotFound, "file not found");
let cli_error: CliError = io_error.into();
assert_eq!(cli_error.exit_code(), 74);
Source§

impl From<Error> for CliError

Source§

fn from(error: Error) -> Self

Converts a JSON serialization error to a CLI error.

Source§

impl From<Error> for CliError

Source§

fn from(error: Error) -> Self

Converts a TOML parsing error to a CLI error.

Source§

impl From<Error> for CliError

Source§

fn from(error: Error) -> Self

Converts a YAML parsing error to a CLI error.

Source§

impl From<Error> for CliError

Source§

fn from(error: Error) -> Self

Converts an anyhow error to a CLI error.

Source§

impl From<RepoError> for CliError

Source§

fn from(error: RepoError) -> Self

Converts a git repository error to a CLI error.

§Examples
use sublime_cli_tools::error::CliError;
use sublime_git_tools::RepoError;

// Example conversion from RepoError to CliError
let git_error = RepoError::OpenRepoFailure(git2::Error::from_str("test"));
let cli_error: CliError = git_error.into();
assert_eq!(cli_error.exit_code(), 70);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more