#[non_exhaustive]pub struct CommandError {
pub headline: String,
pub reason: Option<String>,
pub hint: Option<String>,
pub details: Option<String>,
pub user: bool,
}Expand description
Why a command failed, for people and for the record.
A handler that knows what to tell the user builds one
(CommandError::new, then reason,
hint, details); its user mark
says the headline is in the user’s words. A bare text (String,
&str) or an error (std::io::Error, a boxed error, anyhow’s
through CommandError::from_error) converts to one whose headline
is that text and whose user mark is off: shown to the user, it gets
a generic headline (“Export did not work”) and the text as its
details.
Its Display is the headline, then : and the reason when there is
one: a CommandError made from a text displays that text unchanged,
so code that prints or compares the old String errors keeps working.
use egui_pop_model::commands::CommandError;
let e = CommandError::from("connect: No route to host");
assert_eq!(e.to_string(), "connect: No route to host");
assert!(!e.user);
let e = CommandError::new("cloudy was not added")
.reason("The network found no route to it.")
.hint("Check that cloudy is on and on the same network.")
.details("connect 192.168.1.12:7443: No route to host (os error 113)");
assert!(e.user);
assert_eq!(e.to_string(), "cloudy was not added: The network found no route to it.");Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.headline: StringWhat failed: in the user’s words when user, else the technical
text it was made from.
reason: Option<String>Why, in the user’s words, when known.
hint: Option<String>What the user can do about it.
details: Option<String>The technical chain (an error and its sources, one per line).
user: boolWhether the headline is written for the user (false: a technical
text, shown under a generic headline).
Implementations§
Source§impl CommandError
impl CommandError
Sourcepub fn technical(text: impl Into<String>) -> Self
pub fn technical(text: impl Into<String>) -> Self
A technical failure (user off): the text as its headline.
Sourcepub fn from_error(err: &(dyn Error + 'static)) -> Self
pub fn from_error(err: &(dyn Error + 'static)) -> Self
An error and its sources: its text as the (technical) headline, the whole chain, one per line, as the details.
Trait Implementations§
Source§impl Clone for CommandError
impl Clone for CommandError
Source§fn clone(&self) -> CommandError
fn clone(&self) -> CommandError
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CommandError
impl Debug for CommandError
Source§impl Default for CommandError
impl Default for CommandError
Source§fn default() -> CommandError
fn default() -> CommandError
Source§impl<'de> Deserialize<'de> for CommandError
impl<'de> Deserialize<'de> for CommandError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for CommandError
impl Display for CommandError
Source§impl From<&String> for CommandError
impl From<&String> for CommandError
Source§impl From<&str> for CommandError
impl From<&str> for CommandError
Source§impl From<CommandError> for String
impl From<CommandError> for String
Source§fn from(err: CommandError) -> Self
fn from(err: CommandError) -> Self
Its Display: where a command’s result is still a String.