Struct command_error::OutputError
source · pub struct OutputError { /* private fields */ }
Expand description
An error from a failed command, typically due to a non-zero exit status.
Produced by CommandExt
. This indicates a command that failed, typically with a non-zero
exit code, rather than a command that failed to start (as in ExecError
).
let mut command = Command::new("sh");
command.args(["-c", "echo puppy doggy"]);
let displayed: Utf8ProgramAndArgs = (&command).into();
let error = OutputError::new(
Box::new(displayed),
Box::new(Output {
status: ExitStatus::default(),
stdout: "puppy doggy\n".as_bytes().to_vec(),
stderr: Vec::new(),
})
);
assert_eq!(
error.to_string(),
indoc!(
"`sh` failed: exit status: 0
Command failed: `sh -c 'echo puppy doggy'`
Stdout:
puppy doggy"
),
);
assert_eq!(
error.with_message(Box::new("no kitties found!")).to_string(),
indoc!(
"`sh` failed: no kitties found!
exit status: 0
Command failed: `sh -c 'echo puppy doggy'`
Stdout:
puppy doggy"
)
);
Implementations§
source§impl OutputError
impl OutputError
sourcepub fn new(
command: Box<dyn CommandDisplay + Send + Sync>,
output: Box<dyn OutputLike + Send + Sync>
) -> Self
pub fn new( command: Box<dyn CommandDisplay + Send + Sync>, output: Box<dyn OutputLike + Send + Sync> ) -> Self
Construct a new OutputError
.
sourcepub fn with_message(self, message: Box<dyn DebugDisplay + Send + Sync>) -> Self
pub fn with_message(self, message: Box<dyn DebugDisplay + Send + Sync>) -> Self
Attach a user-defined message to this error.
sourcepub fn without_message(self) -> Self
pub fn without_message(self) -> Self
Remove a user-defined message from this error, if any.
Trait Implementations§
source§impl Debug for OutputError
impl Debug for OutputError
source§impl Display for OutputError
impl Display for OutputError
source§impl Error for OutputError
impl Error for OutputError
1.30.0 · source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. Read more
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
source§impl From<OutputError> for Error
impl From<OutputError> for Error
source§fn from(error: OutputError) -> Self
fn from(error: OutputError) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for OutputError
impl !RefUnwindSafe for OutputError
impl Send for OutputError
impl Sync for OutputError
impl Unpin for OutputError
impl !UnwindSafe for OutputError
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
Mutably borrows from an owned value. Read more