From e820a41651e70a41cfd6836340f5c0ebe7ea7980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Audiger?= Date: Tue, 27 Jan 2026 20:52:56 +0100 Subject: [PATCH 1/2] chore(bake): use collect pattern when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémy Audiger --- crates/brioche-core/src/bake.rs | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/crates/brioche-core/src/bake.rs b/crates/brioche-core/src/bake.rs index 4e1f1365..15c567e3 100644 --- a/crates/brioche-core/src/bake.rs +++ b/crates/brioche-core/src/bake.rs @@ -660,30 +660,22 @@ impl std::fmt::Display for BakeFailed { message_lines.retain(|line| !line.trim().is_empty()); let message = message_lines.join("\n"); - let mut sources = vec![]; - let mut seen_sources = HashSet::new(); - // 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); - } - } + let mut seen_sources = HashSet::new(); + let sources = 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())) + .collect::>(); write!(f, "{message}")?; for source in &sources { From e1fd303064346e42dd0befbdefb9acda020991c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Audiger?= Date: Tue, 27 Jan 2026 21:22:07 +0100 Subject: [PATCH 2/2] refactor(bake): update BakeFailed Display trait to be more rust iodiomatic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémy Audiger --- crates/brioche-core/src/bake.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/brioche-core/src/bake.rs b/crates/brioche-core/src/bake.rs index 15c567e3..71e5c7ed 100644 --- a/crates/brioche-core/src/bake.rs +++ b/crates/brioche-core/src/bake.rs @@ -657,15 +657,17 @@ impl std::fmt::Display for BakeFailed { .message .lines() .partition::, _>(|line| line.trim_start().starts_with("at ")); + message_lines.retain(|line| !line.trim().is_empty()); let message = message_lines.join("\n"); + 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. let mut seen_sources = HashSet::new(); - let sources = message_sources + message_sources .into_iter() .map(|s| { s.trim_start() @@ -675,12 +677,7 @@ impl std::fmt::Display for BakeFailed { }) .chain(self.meta.source.iter().flatten().map(ToString::to_string)) .filter(|source| seen_sources.insert(source.clone())) - .collect::>(); - - write!(f, "{message}")?; - for source in &sources { - write!(f, "\n at {source}")?; - } + .try_for_each(|source| write!(f, "\n at {source}"))?; Ok(()) }