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 settingsValidation: Invalid arguments, invalid stateExecution: Command failures, operation failuresGit: Repository errors, git operation failuresPackage: Package.json issues, dependency problemsIo: File system errors, permission issuesNetwork: Registry unreachable, download failuresUser: 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
impl CliError
Sourcepub fn configuration(msg: impl Into<String>) -> Self
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);Sourcepub fn validation(msg: impl Into<String>) -> Self
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);Sourcepub fn execution(msg: impl Into<String>) -> Self
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);Sourcepub fn git(msg: impl Into<String>) -> Self
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);Sourcepub fn package(msg: impl Into<String>) -> Self
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);Sourcepub fn io(msg: impl Into<String>) -> Self
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);Sourcepub fn network(msg: impl Into<String>) -> Self
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);Sourcepub fn user(msg: impl Into<String>) -> Self
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);Sourcepub fn exit_code(&self) -> i32
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);Sourcepub fn user_message(&self) -> String
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"));Sourcepub fn kind(&self) -> &'static str
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
impl AsRef<str> for CliError
Source§fn as_ref(&self) -> &str
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 Error for CliError
impl Error for CliError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
Source§impl From<Error> for CliError
impl From<Error> for CliError
Source§fn from(error: Error) -> Self
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<RepoError> for CliError
impl From<RepoError> for CliError
Source§fn from(error: RepoError) -> Self
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§
impl Freeze for CliError
impl RefUnwindSafe for CliError
impl Send for CliError
impl Sync for CliError
impl Unpin for CliError
impl UnwindSafe for CliError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.