Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 14 additions & 25 deletions crates/brioche-core/src/bake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,38 +657,27 @@ impl std::fmt::Display for BakeFailed {
.message
.lines()
.partition::<Vec<_>, _>(|line| line.trim_start().starts_with("at "));

message_lines.retain(|line| !line.trim().is_empty());
let message = message_lines.join("\n");

let mut sources = vec![];
let mut seen_sources = HashSet::new();
write!(f, "{message}")?;

// HACK: Currently, detailed errors get converted to and from strings
// via `anyhow`. To properly print all source lines without duplicates,
// we do our best to parse the error message. This should instead be
// handled by keeping structured errors throughout.
for source in message_sources {
let source = source
.trim_start()
.strip_prefix("at ")
.expect("invalid line")
.to_string();
if seen_sources.insert(source.clone()) {
sources.push(source);
}
}

for source in self.meta.source.iter().flatten() {
let source = source.to_string();
if seen_sources.insert(source.clone()) {
sources.push(source);
}
}

write!(f, "{message}")?;
for source in &sources {
write!(f, "\n at {source}")?;
}
let mut seen_sources = HashSet::new();
message_sources
.into_iter()
.map(|s| {
s.trim_start()
.strip_prefix("at ")
.expect("invalid line")
.to_string()
})
.chain(self.meta.source.iter().flatten().map(ToString::to_string))
.filter(|source| seen_sources.insert(source.clone()))
.try_for_each(|source| write!(f, "\n at {source}"))?;

Ok(())
}
Expand Down