Skip to main content

report_and_classify

Function report_and_classify 

Source
pub fn report_and_classify(err: &Error) -> ExitCode
Expand description

Prints err to stderr, then classifies it into a semantic ExitCode.

Structurally matches anyhow’s default main-error format (a summary line, then a numbered “Caused by:” section for any further causes), but with each cause’s own text — not anyhow’s surrounding structure — passed through escape_error_text before printing. Classification is via classify_exit_code.

Shared by execute_command (command-handler failures) and main (pre-dispatch failures, e.g. an invalid --format value), so every failure this CLI can produce is reported and exits the same way. An error’s cause chain can embed content from an untrusted MCP server (e.g. a JSON-RPC error message), and both anyhow::Error’s Debug rendering and the thiserror-derived Display impls it walks interpolate that content verbatim — so err’s formatted report is sanitized via sanitized_error_report before printing.

§Examples

use mcp_execution_cli::runner;
use mcp_execution_core::Error as CoreError;
use mcp_execution_core::cli::ExitCode;

let err = anyhow::Error::from(CoreError::InvalidArgument(
    "invalid output format: 'xml' (expected: json, text, or pretty)".to_string(),
));
assert_eq!(runner::report_and_classify(&err), ExitCode::INVALID_INPUT);