MCPcopy Create free account
hub / github.com/csskit/csskit / format_diagnostic_error

Function format_diagnostic_error

crates/csskit/src/commands/mod.rs:87–99  ·  view source on GitHub ↗
(err: &Diagnostic, source: &str, file_name: &str)

Source from the content-addressed store, hash-verified

85}
86
87pub fn format_diagnostic_error(err: &Diagnostic, source: &str, file_name: &str) -> String {
88 use miette::{GraphicalReportHandler, GraphicalTheme, NamedSource};
89 let handler = GraphicalReportHandler::new_themed(GraphicalTheme::unicode_nocolor());
90 let mut report = String::new();
91 let named = NamedSource::new(file_name, source.to_string());
92 let miette_err = err.into_diagnostic(source);
93 let err_with_source = miette::Report::new(miette_err).with_source_code(named);
94 if handler.render_report(&mut report, &*err_with_source).is_ok() {
95 return report;
96 }
97 let DiagnosticMeta { code, message, help, .. } = (err.formatter)(err, source);
98 format!("Error [{code}]: {message}\nHelp: {help}\n")
99}

Callers 5

runMethod · 0.85
runMethod · 0.85
runMethod · 0.85
runMethod · 0.85
runMethod · 0.85

Calls 1

into_diagnosticMethod · 0.80

Tested by

no test coverage detected