Skip to main content

format_error

Function format_error 

Source
pub fn format_error(error: &DynamicCliError) -> String
Expand description

Format an error as a colored, human-readable string

Generates a string suitable for display in the terminal. The format is:

Error: <main message>
  ℹ  <actionable suggestion>

For parse errors with Levenshtein suggestions, a “Did you mean:” block is appended instead of the line.

§Arguments

  • error - The error to format

§Example

use dynamic_cli::error::{format_error, ConfigError};
use std::path::PathBuf;

let error: dynamic_cli::error::DynamicCliError = ConfigError::FileNotFound {
    path: PathBuf::from("config.yaml"),
    suggestion: Some("Verify the path and file permissions.".to_string()),
}.into();

let formatted = format_error(&error);
assert!(formatted.contains("Error:"));
assert!(formatted.contains("config.yaml"));