fix(cli): print clean error chain instead of anyhow Debug with backtrace
When RUST_BACKTRACE was set in the environment, every user-facing error dumped a 20-line Rust backtrace at the user — e.g. running 'onyx list show' with no workspace gave them a stack trace through anyhow, clap, and libc start. Replace 'fn main() -> Result' with an explicit error printer that walks the anyhow cause chain using Display, and exits 1. Programming-bug panics still surface through the default panic handler.
This commit is contained in:
parent
433a950418
commit
8a81f05492
|
|
@ -3,6 +3,7 @@ mod output;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
use colored::Colorize;
|
||||||
use commands::*;
|
use commands::*;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
|
@ -197,7 +198,24 @@ enum GroupCommands {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() {
|
||||||
|
match run() {
|
||||||
|
Ok(()) => {}
|
||||||
|
Err(e) => {
|
||||||
|
// Print user-friendly error chain (no backtrace). Programming-bug
|
||||||
|
// panics still surface through their default handler.
|
||||||
|
eprintln!("{}: {}", "Error".red().bold(), e);
|
||||||
|
let mut cause = e.source();
|
||||||
|
while let Some(c) = cause {
|
||||||
|
eprintln!(" caused by: {}", c);
|
||||||
|
cause = c.source();
|
||||||
|
}
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run() -> Result<()> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue