From 8b91a0bfbf0097d145359c8508a61696ade812d1 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 22 Jun 2026 16:41:21 +0400 Subject: fix: make core error displays actionable --- crates/fparkan-path/src/lib.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'crates/fparkan-path/src') diff --git a/crates/fparkan-path/src/lib.rs b/crates/fparkan-path/src/lib.rs index f59fda0..330b03a 100644 --- a/crates/fparkan-path/src/lib.rs +++ b/crates/fparkan-path/src/lib.rs @@ -97,7 +97,14 @@ pub enum PathError { impl fmt::Display for PathError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{self:?}") + match self { + Self::Empty => write!(f, "path is empty"), + Self::EmbeddedNul => write!(f, "path contains an embedded NUL byte"), + Self::Absolute => write!(f, "path must be relative and cannot be absolute"), + Self::ParentTraversal => write!(f, "path attempts to traverse outside its root"), + Self::EscapesRoot => write!(f, "normalized path escapes the configured root"), + Self::InvalidUtf8 => write!(f, "path is not valid UTF-8 after normalization"), + } } } @@ -229,6 +236,18 @@ mod tests { ); } + #[test] + fn path_error_display_is_actionable() { + assert_eq!( + PathError::ParentTraversal.to_string(), + "path attempts to traverse outside its root" + ); + assert_eq!( + PathError::EmbeddedNul.to_string(), + "path contains an embedded NUL byte" + ); + } + #[test] fn strict_legacy_rejects_host_only_segments() { assert_eq!( -- cgit v1.2.3