From 079fd94c0c68774face68148c71262420ec85522 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 15 May 2026 20:39:45 +0000 Subject: [PATCH] fix(diffguard-core): propagate GlobSetBuilder error instead of panicking (#1475) `compile_filter_globs` called `.expect()` on `GlobSetBuilder::build()`, which would panic on failure rather than returning an error from a function that already returns `Result<_, PathFilterError>`. Add a `PathFilterError::GlobSetBuild` variant and replace the `.expect()` with `.map_err(...)` so the failure is surfaced through the existing error path, matching how `Glob::new()` errors are handled above. --- crates/diffguard-core/src/check.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/diffguard-core/src/check.rs b/crates/diffguard-core/src/check.rs index 37dd641f..8513cb25 100644 --- a/crates/diffguard-core/src/check.rs +++ b/crates/diffguard-core/src/check.rs @@ -79,6 +79,8 @@ pub enum PathFilterError { glob: String, source: globset::Error, }, + #[error("failed to build path filter glob set: {source}")] + GlobSetBuild { source: globset::Error }, } /// Run a policy check over a unified diff text. @@ -265,7 +267,8 @@ fn compile_filter_globs(globs: &[String]) -> Result { })?; b.add(glob); } - Ok(b.build().expect("globset build should succeed")) + b.build() + .map_err(|source| PathFilterError::GlobSetBuild { source }) } /// Filter a rule based on tag criteria in the plan. @@ -436,6 +439,9 @@ mod tests { let err = compile_filter_globs(&["[".to_string()]).unwrap_err(); match err { PathFilterError::InvalidGlob { glob, .. } => assert_eq!(glob, "["), + PathFilterError::GlobSetBuild { .. } => { + panic!("expected InvalidGlob, got GlobSetBuild") + } } }