cli: Improve consistency of error messages
This commit is contained in:
parent
ea4104dbd7
commit
2d7193f4bc
|
|
@ -76,10 +76,7 @@ pub fn run(
|
||||||
|
|
||||||
if !errors.is_empty() {
|
if !errors.is_empty() {
|
||||||
for (title, id, error) in errors {
|
for (title, id, error) in errors {
|
||||||
term::error(format!(
|
term::error(format!("patch {title:?} ({id}) failed to load: {error}",));
|
||||||
"{} Patch {title:?} ({id}) failed to load: {error}",
|
|
||||||
term::format::negative("Error:")
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,9 +110,9 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
||||||
|
|
||||||
if !validations.is_empty() {
|
if !validations.is_empty() {
|
||||||
for err in validations {
|
for err in validations {
|
||||||
term::error(format!("Error: validation error {err}"));
|
term::error(format!("validation error: {err}"));
|
||||||
}
|
}
|
||||||
anyhow::bail!("fatal error: repository storage is corrupt");
|
anyhow::bail!("fatal: repository storage is corrupt");
|
||||||
}
|
}
|
||||||
|
|
||||||
term::success!(
|
term::success!(
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ fn main() {
|
||||||
Ok(_) => process::exit(0),
|
Ok(_) => process::exit(0),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if let Some(err) = err {
|
if let Some(err) = err {
|
||||||
term::error(format!("Error: rad: {err}"));
|
term::error(format!("rad: {err}"));
|
||||||
}
|
}
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
@ -277,7 +277,7 @@ fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyhow::Error>>
|
||||||
rad_remote::run,
|
rad_remote::run,
|
||||||
args.to_vec(),
|
args.to_vec(),
|
||||||
),
|
),
|
||||||
_ => {
|
other => {
|
||||||
let exe = format!("{NAME}-{exe}");
|
let exe = format!("{NAME}-{exe}");
|
||||||
let status = process::Command::new(exe.clone()).args(args).status();
|
let status = process::Command::new(exe.clone()).args(args).status();
|
||||||
|
|
||||||
|
|
@ -289,7 +289,9 @@ fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyhow::Error>>
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
if let ErrorKind::NotFound = err.kind() {
|
if let ErrorKind::NotFound = err.kind() {
|
||||||
return Err(Some(anyhow!("command `{}` not found", exe)));
|
return Err(Some(anyhow!(
|
||||||
|
"`{other}` is not a command. See `rad --help` for a list of commands.",
|
||||||
|
)));
|
||||||
} else {
|
} else {
|
||||||
return Err(Some(err.into()));
|
return Err(Some(err.into()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ where
|
||||||
}
|
}
|
||||||
Some(Error::HelpManual) => {
|
Some(Error::HelpManual) => {
|
||||||
let Ok(status) = term::manual(help.name) else {
|
let Ok(status) = term::manual(help.name) else {
|
||||||
perror(help.name, "failed to load manual page");
|
io::error(format!("rad {}: failed to load manual page", help.name));
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
};
|
};
|
||||||
process::exit(status.code().unwrap_or(0));
|
process::exit(status.code().unwrap_or(0));
|
||||||
|
|
@ -98,10 +98,10 @@ where
|
||||||
Some(Error::WithHint { hint, .. }) => Some(hint),
|
Some(Error::WithHint { hint, .. }) => Some(hint),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
perror(help.name, &err);
|
io::error(format!("rad {}: {err}", help.name));
|
||||||
|
|
||||||
if let Some(hint) = hint {
|
if let Some(hint) = hint {
|
||||||
eprintln!("{}", Paint::yellow(hint));
|
io::hint(hint);
|
||||||
}
|
}
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
@ -128,23 +128,15 @@ pub fn profile() -> Result<Profile, anyhow::Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn perror(name: &str, err: impl std::fmt::Display) {
|
|
||||||
eprintln!(
|
|
||||||
"{ERROR_PREFIX} {} rad {}: {err}",
|
|
||||||
Paint::red("Error:"),
|
|
||||||
name,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn fail(_name: &str, error: &anyhow::Error) {
|
pub fn fail(_name: &str, error: &anyhow::Error) {
|
||||||
let err = error.to_string();
|
let err = error.to_string();
|
||||||
let err = err.trim_end();
|
let err = err.trim_end();
|
||||||
|
|
||||||
for line in err.lines() {
|
for line in err.lines() {
|
||||||
println!("{ERROR_PREFIX} {} {line}", Paint::red("Error:"));
|
io::error(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(Error::WithHint { hint, .. }) = error.downcast_ref::<Error>() {
|
if let Some(Error::WithHint { hint, .. }) = error.downcast_ref::<Error>() {
|
||||||
println!("{ERROR_HINT_PREFIX} {}", Paint::yellow(hint));
|
io::hint(hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,11 @@ pub fn warning(warning: impl fmt::Display) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn error(error: impl fmt::Display) {
|
pub fn error(error: impl fmt::Display) {
|
||||||
println!("{ERROR_PREFIX} {error}");
|
println!("{ERROR_PREFIX} {} {error}", Paint::red("Error:"));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn hint(hint: impl fmt::Display) {
|
||||||
|
println!("{ERROR_HINT_PREFIX} {}", Paint::yellow(hint));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ask<D: fmt::Display>(prompt: D, default: bool) -> bool {
|
pub fn ask<D: fmt::Display>(prompt: D, default: bool) -> bool {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue