diff options
author | Florian Klink <flokli@flokli.de> | 2023-07-20T11·37+0300 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2023-07-21T19·06+0000 |
commit | 7971d7d9ff42ed00f6f70121f372dd744f45915b (patch) | |
tree | 57e89f31b8b31e6c997c730af5b7b452aa7cc4fb | |
parent | a6580748aabe7fcbea735396ac700661b6c53e87 (diff) |
feat(tvix/nix-compat/store_path): store position in InvalidName r/6438
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 <tvl@lahfa.xyz> Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de>
-rw-r--r-- | tvix/nix-compat/src/store_path/mod.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs index 74dc5949076b..6372b39d75cc 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<u8>), + #[error("Invalid name: {:?}, character at position {} ('{}') is invalid", .0, .1, .0[1])] + InvalidName(Vec<u8>, 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<String, Error> { - 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<String, Error> { continue; } - return Err(Error::InvalidName(s.to_vec())); + return Err(Error::InvalidName(s.to_vec(), i)); } Ok(String::from_utf8(s.to_vec()).unwrap()) |