From 7971d7d9ff42ed00f6f70121f372dd744f45915b Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 20 Jul 2023 14:37:04 +0300 Subject: feat(tvix/nix-compat/store_path): store position in InvalidName Add the position in the string where the name is problematic. Change-Id: If6fd8be6100b718f8d68568eafc77ebb3cfb82d0 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8979 Reviewed-by: raitobezarius Tested-by: BuildkiteCI Autosubmit: flokli --- tvix/nix-compat/src/store_path/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tvix/nix-compat/src/store_path/mod.rs') diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs index 74dc594907..6372b39d75 100644 --- a/tvix/nix-compat/src/store_path/mod.rs +++ b/tvix/nix-compat/src/store_path/mod.rs @@ -28,8 +28,8 @@ pub enum Error { InvalidHashEncoding(Nixbase32DecodeError), #[error("Invalid length")] InvalidLength(), - #[error("Invalid name: {0:?}")] - InvalidName(Vec), + #[error("Invalid name: {:?}, character at position {} ('{}') is invalid", .0, .1, .0[1])] + InvalidName(Vec, usize), #[error("Tried to parse an absolute path which was missing the store dir prefix.")] MissingStoreDir(), } @@ -139,7 +139,7 @@ impl StorePath { /// Checks a given &[u8] to match the restrictions for store path names, and /// returns the name as string if successful. pub(crate) fn validate_name(s: &[u8]) -> Result { - for c in s { + for (i, c) in s.iter().enumerate() { if c.is_ascii_alphanumeric() || *c == b'-' || *c == b'_' @@ -151,7 +151,7 @@ pub(crate) fn validate_name(s: &[u8]) -> Result { continue; } - return Err(Error::InvalidName(s.to_vec())); + return Err(Error::InvalidName(s.to_vec(), i)); } Ok(String::from_utf8(s.to_vec()).unwrap()) -- cgit 1.4.1