Struct UserFacingError

Source
pub struct UserFacingError { /* private fields */ }
Expand description

The eponymous struct. You can create a new one from using user_error::UserFacingError::new() however I recommend you use your own error types and have them implement UFE instead of using UserFacingError directly. This is more of an example type, or a way to construct a pretty messages without implementing your own error type.

Implementations§

Source§

impl UserFacingError

Source

pub fn new<S: Into<String>>(summary: S) -> UserFacingError

This is how users create a new User Facing Error. The value passed to new() will be used as an error summary. Error summaries are displayed first, prefixed by ’Error: ’.

§Example
let err = UserFacingError::new("File failed to open");
Source

pub fn update<S: Into<String>>(&mut self, summary: S)

Replace the error summary.

§Example
let mut err = UserFacingError::new("File failed to open");
err.update("Failed Task");
Source

pub fn push<S: Into<String>>(&mut self, new_summary: S)

Replace the error summary and add the previous error summary to the list of reasons

§Example
let mut err = UserFacingError::new("File failed to open");
err.push("Failed Task");
Source

pub fn reason<S: Into<String>>(self, reason: S) -> UserFacingError

Add a reason to the UserFacingError. Reasons are displayed in a bulleted list below the summary, in the reverse order they were added.

§Example
let err = UserFacingError::new("File failed to open")
                            .reason("File not found")
                            .reason("Directory cannot be entered");
Source

pub fn clear_reasons(&mut self)

Clears all reasons from a UserFacingError.

§Example
let mut err = UserFacingError::new("File failed to open")
                            .reason("File not found")
                            .reason("Directory cannot be entered");
err.clear_reasons();
Source

pub fn help<S: Into<String>>(self, helptext: S) -> UserFacingError

Add help text to the error. Help text is displayed last, in a muted fashion.

§Example
let err = UserFacingError::new("File failed to open")
                            .reason("File not found")
                            .help("Check if the file exists.");
Source

pub fn clear_helptext(&mut self)

Clears all the help text from a UserFacingError.

§Example
let mut err = UserFacingError::new("File failed to open")
                            .reason("File not found")
                            .reason("Directory cannot be entered")
                            .help("Check if the file exists.");
err.clear_helptext();

Trait Implementations§

Source§

impl Debug for UserFacingError

Source§

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

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

impl Display for UserFacingError

Source§

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

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

impl Error for UserFacingError

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<&dyn Error> for UserFacingError

Allows you to create UserFacingErrors From std Errors. You should really just implement UFE for your error type, but if you wanted to convert before quitting so you could add help text of something you can use this.

Source§

fn from(error: &dyn Error) -> UserFacingError

Converts to this type from the input type.
Source§

impl From<Box<dyn Error>> for UserFacingError

Allows you to create UserFacingErrors From std Errors. You should really just implement UFE for your error type, but if you wanted to convert before quitting so you could add help text of something you can use this.

Source§

fn from(error: Box<dyn Error>) -> UserFacingError

Converts to this type from the input type.
Source§

impl From<Error> for UserFacingError

Allows you to create UserFacingErrors From std::io::Error for convenience You should really just implement UFE for your error type, but if you wanted to convert before quitting so you could add help text of something you can use this.

Source§

fn from(error: Error) -> UserFacingError

Converts to this type from the input type.
Source§

impl<T: Debug> From<Result<T, Box<dyn Error>>> for UserFacingError

Allows you to create UserFacingErrors From std Errors wrapped in a Result You should really just implement UFE for your error type, but if you wanted to convert before quitting so you could add help text of something you can use this.

Source§

fn from(error: Result<T, Box<dyn Error>>) -> UserFacingError

Converts to this type from the input type.
Source§

impl UFE for UserFacingError

Source§

fn summary(&self) -> String

Returns a summary of the error. This will be printed in red, prefixed by “Error: “, at the top of the error message.
Source§

fn reasons(&self) -> Option<Vec<String>>

Returns a vector of Strings that will be listed as bullet points below the summary. By default, lists any errors returned by .source() recursively.
Source§

fn helptext(&self) -> Option<String>

Returns help text that is listed below the reasons in a muted fashion. Useful for additional details, or suggested next steps.
Source§

fn print(&self)

Prints the formatted error. Read more
Source§

fn print_and_exit(&self)

Convenience function that pretty prints the error and exits the program. Read more
Source§

fn into_ufe(&self) -> UserFacingError

Consumes the UFE and returns a UserFacingError. Useful if you want access to additional functions to edit the error message before exiting the program. Read more

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, 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> 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, 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.