#[expect(
clippy::arithmetic_side_effects,
reason = "bounds-checked index arithmetic"
)]
pub fn extract_key_from_toml_error(error: &str) -> String {
if let Some(start) = error.find('`') {
if let Some(end) = error[start + 1..].find('`') {
return error[start + 1..start + 1 + end].to_string();
}
}
"unknown".to_string()
}
pub fn format_invalid_type_message(error: &str) -> String {
if error.contains("invalid type") {
if let Some(start) = error.find("invalid type: ") {
let rest = &error[start + 13..];
if let Some(comma) = rest.find(',') {
let actual = &rest[..comma];
if let Some(expected_start) = rest.find("expected ") {
let expected_part = &rest[expected_start + 9..];
if let Some(end) = expected_part.find(' ') {
return format!("Expected {}, got {}", &expected_part[..end], actual);
}
}
return format!("Invalid value: {actual}");
}
}
}
error.to_string()
}