Enum human_errors::Error [−][src]
The fundamental error type used by this library.
An error type which encapsulates information about whether an error is the result of something the user did, or a system failure outside of their control. These errors include a description of what occurred, advice on how to proceed and references to the causal chain which led to this failure.
Examples
use human_errors; let err = human_errors::user( "We could not open the config file you provided.", "Make sure that the file exists and is readable by the application.", ); // Prints the error and any advice for the user. println!("{}", err)
Variants
An error which was the result of actions that the user took.
These errors are usually things which a user can easily resolve by changing how they interact with the system. Advice should be used to guide the user to the correct interaction paths and help them self-mitigate without needing to open support tickets.
These errors are usually generated with crate::user
, crate::user_with_cause
and crate::user_with_internal
.
An error which was the result of the system failing rather than the user's actions.
These kinds of issues are usually the result of the system entering an unexpected state and/or violating an assumption on behalf of the developer. Often these issues cannot be resolved by the user directly, so the advice should guide them to the best way to raise a bug with you and provide you with information to help them fix the issue.
These errors are usually generated with crate::system
, crate::system_with_cause
and crate::system_with_internal
.
Implementations
impl Error
[src]
pub fn description(&self) -> String
[src]
Gets the description message from this error.
Gets the description which was provided as the first argument when constructing this error.
Examples
use human_errors; let err = human_errors::user( "We could not open the config file you provided.", "Make sure that the file exists and is readable by the application.", ); // Prints: "We could not open the config file you provided." println!("{}", err.description())
pub fn message(&self) -> String
[src]
Gets the formatted error and its advice.
Generates a string containing the description of the error and any causes, as well as a list of suggestions for how a user should deal with this error. The "deepest" error's advice is presented first, with successively higher errors appearing lower in the list. This is done because the most specific error is the one most likely to have the best advice on how to resolve the problem.
Examples
use human_errors; let err = human_errors::user_with_cause( "We could not open the config file you provided.", "Make sure that you've specified a valid config file with the --config option.", human_errors::user( "We could not find a file at /home/user/.config/demo.yml", "Make sure that the file exists and is readable by the application." ) ); // Prints a message like the following: // Oh no! We could not open the config file you provided. // // This was caused by: // We could not find a file at /home/user/.config/demo.yml // // To try and fix this, you can: // - Make sure that the file exists and is readable by the application. // - Make sure that you've specified a valid config file with the --config option. println!("{}", err.message());
pub fn is_user(&self) -> bool
[src]
Checks if this error is a user error.
Returns true
if this error is a Error::UserError,
otherwise false
.
Examples
use human_errors; let err = human_errors::user( "We could not open the config file you provided.", "Make sure that the file exists and is readable by the application.", ); // Prints "is_user?: true" println!("is_user?: {}", err.is_user());
pub fn is_system(&self) -> bool
[src]
Checks if this error is a system error.
Returns true
if this error is a Error::SystemError,
otherwise false
.
Examples
use human_errors; let err = human_errors::system( "Failed to generate config file.", "Please file an error report on GitHub." ); // Prints "is_system?: true" println!("is_system?: {}", err.is_system());
Trait Implementations
impl Debug for Error
[src]
impl Display for Error
[src]
impl Error for Error
[src]
fn source(&self) -> Option<&(dyn Error + 'static)>
[src]
pub fn backtrace(&self) -> Option<&Backtrace>
[src]
pub fn description(&self) -> &str
1.0.0[src]
pub fn cause(&self) -> Option<&dyn Error>
1.0.0[src]
impl From<Error> for Error
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Error
impl Send for Error
impl Sync for Error
impl Unpin for Error
impl !UnwindSafe for Error
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,