Add helpers for manipulating errors

This commit is contained in:
Shunsuke Shibayama 2022-12-10 02:40:55 +09:00
parent 3013d708d8
commit 747974d37c
2 changed files with 29 additions and 0 deletions

View file

@ -642,6 +642,19 @@ impl ErrorCore {
)
}
pub fn get_loc_with_fallback(&self) -> Location {
if self.loc == Location::Unknown {
for sub in &self.sub_messages {
if sub.loc != Location::Unknown {
return sub.loc;
}
}
Location::Unknown
} else {
self.loc
}
}
pub fn fmt_header(&self, color: Color, caused_by: &str, input: &str) -> String {
let loc = match self.loc {
Location::Range {