From 52310761f67220c9c075cd847205825a720035ee Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 21 Feb 2026 23:38:32 +0900 Subject: feat(console): add structured error handling, verbosity, and suggestions Implement Phase 7.2 error handling & UX infrastructure: - Add exit_code module with MozartError, bail()/bail_silent() helpers, and Composer-compatible exit code constants (0-5, 100) - Redesign Console struct with Verbosity enum (Quiet/Normal/Verbose/ VeryVerbose/Debug), ANSI auto-detection via IsTerminal, and verbosity-gated output methods (info/verbose/debug/error) - Thread Console through all 33 command execute() signatures - Replace all std::process::exit() calls with structured MozartError returns handled in main() - Migrate eprintln\! status messages to console.info() for quiet-mode suppression - Add suggest module with Levenshtein distance and "Did you mean?" formatting for future package name suggestions Co-Authored-By: Claude Opus 4.6 --- crates/mozart/src/main.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'crates/mozart/src/main.rs') diff --git a/crates/mozart/src/main.rs b/crates/mozart/src/main.rs index cd85137..dd85279 100644 --- a/crates/mozart/src/main.rs +++ b/crates/mozart/src/main.rs @@ -1,7 +1,24 @@ use clap::Parser; use mozart::commands; +use mozart::exit_code; -fn main() -> anyhow::Result<()> { +fn main() { let cli = commands::Cli::parse(); - commands::execute(&cli) + match commands::execute(&cli) { + Ok(()) => {} + Err(e) => { + // Check if this is a structured MozartError with a specific exit code. + if let Some(mozart_err) = e.downcast_ref::() { + // Only print a message when there is one (bail_silent produces empty message). + if !mozart_err.message.is_empty() { + eprintln!("{}", mozart::console::error(&mozart_err.message)); + } + std::process::exit(mozart_err.exit_code); + } + + // Generic anyhow error — print and exit with GENERAL_ERROR. + eprintln!("{}", mozart::console::error(&format!("{e:#}"))); + std::process::exit(exit_code::GENERAL_ERROR); + } + } } -- cgit v1.3.1