Crate command_error
source ·Expand description
command_error
provides the CommandExt
trait, which runs a command and checks its exit
status:
use std::process::Command;
use command_error::CommandExt;
let err = Command::new("sh")
.args(["-c", "echo puppy; false"])
.output_checked_utf8()
.unwrap_err();
assert_eq!(
err.to_string(),
indoc!(
"`sh` failed: exit status: 1
Command failed: `sh -c 'echo puppy; false'`
Stdout:
puppy"
)
);
Error messages are detailed and helpful. Additional methods are provided for overriding
the default success logic (for that weird tool that thinks 2
is a reasonable exit code) and
for transforming the output (for example, to parse command output as JSON while retaining
information about the command that produced the output in the error message).
§Enforcing use of command_error
If you’d like to make sure that CommandExt
methods are used instead of the plain
Command
methods in your project, you can add a stanza like this to
clippy.toml
at your project root:
[[disallowed-methods]]
path = "std::process::Command::output"
reason = "Use command_error::CommandExt::output_checked[_with][_utf8]"
[[disallowed-methods]]
path = "std::process::Command::status"
reason = "Use command_error::CommandExt::status_checked[_with]"
[[disallowed-methods]]
path = "std::process::Command::spawn"
reason = "Use command_error::CommandExt::spawn_checked"
[[disallowed-methods]]
path = "std::process::Child::try_wait"
reason = "Use command_error::ChildExt::try_wait_checked[_with]"
[[disallowed-methods]]
path = "std::process::Child::wait"
reason = "Use command_error::ChildExt::wait_checked[_with]"
[[disallowed-methods]]
path = "std::process::Child::wait_with_output"
reason = "Use command_error::ChildExt::output_checked[_with][_utf8]"
Structs§
- An error from failing to execute a command. Produced by
CommandExt
. - An error produced when attempting to convert
Command
Output
to a custom format (such asUtf8Output
). - An error from a failed command, typically due to a non-zero exit status.
- An optional
ExitStatus
combined with context about theCommand
that produced it. - A program name and arguments stored as UTF-8
String
s. - An error from failing to wait for a command. Produced by
ChildExt
.
Enums§
- An error produced by a
Command
failure.