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() {
|
||||
for (title, id, error) in errors {
|
||||
term::error(format!(
|
||||
"{} Patch {title:?} ({id}) failed to load: {error}",
|
||||
term::format::negative("Error:")
|
||||
));
|
||||
term::error(format!("patch {title:?} ({id}) failed to load: {error}",));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -110,9 +110,9 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
|
|||
|
||||
if !validations.is_empty() {
|
||||
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!(
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ fn main() {
|
|||
Ok(_) => process::exit(0),
|
||||
Err(err) => {
|
||||
if let Some(err) = err {
|
||||
term::error(format!("Error: rad: {err}"));
|
||||
term::error(format!("rad: {err}"));
|
||||
}
|
||||
process::exit(1);
|
||||
}
|
||||
|
|
@ -277,7 +277,7 @@ fn run_other(exe: &str, args: &[OsString]) -> Result<(), Option<anyhow::Error>>
|
|||
rad_remote::run,
|
||||
args.to_vec(),
|
||||
),
|
||||
_ => {
|
||||
other => {
|
||||
let exe = format!("{NAME}-{exe}");
|
||||
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) => {
|
||||
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 {
|
||||
return Err(Some(err.into()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ where
|
|||
}
|
||||
Some(Error::HelpManual) => {
|
||||
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(status.code().unwrap_or(0));
|
||||
|
|
@ -98,10 +98,10 @@ where
|
|||
Some(Error::WithHint { hint, .. }) => Some(hint),
|
||||
None => None,
|
||||
};
|
||||
perror(help.name, &err);
|
||||
io::error(format!("rad {}: {err}", help.name));
|
||||
|
||||
if let Some(hint) = hint {
|
||||
eprintln!("{}", Paint::yellow(hint));
|
||||
io::hint(hint);
|
||||
}
|
||||
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) {
|
||||
let err = error.to_string();
|
||||
let err = err.trim_end();
|
||||
|
||||
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>() {
|
||||
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) {
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Reference in New Issue