File size: 1,526 Bytes
07bbbbf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
use colored::Colorize;
pub fn format_error(error: &mdx::ZdbError) -> String{
let mut output = String::new();
output.push_str(&format!("Error: {}\n", error.to_string().red().bold()));
if let Some(backtrace) = mdx::snafu::ErrorCompat::backtrace(error){
// Add backtrace header in red, mimicking color-backtrace
output.push_str(&format!("{}:\n", "BACKTRACE"));
// Convert backtrace to string and split into lines
let backtrace_str = format!("{}", backtrace);
for line in backtrace_str.lines() {
let line = line.trim();
if line.is_empty() {
continue;
}
if line.starts_with("at ") {
if let Some((_, file_info)) = line.split_once("at ") {
let file_info = file_info.trim().green();
output.push_str(&format!(" at {}\n", file_info));
} else {
output.push_str(&format!(" {}\n", line.white()));
}
}else{
// Check if line starts with a frame number (e.g., "0:", "1:")
if let Some((frame_num, rest)) = line.split_once(':') {
output.push_str(&format!("{}: {}\n", frame_num.trim().yellow().bold(), rest.cyan()));
} else {
// Fallback for unexpected line formats
output.push_str(&format!("{}\n", line.white()));
}
}
}
}
output
}
|