From 09a901de5bde8a583d50fe4086c5128c6c0114c7 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 23 Sep 2023 11:48:20 +0300 Subject: feat(tvix/nix-compat): fix and improve error message Similar to cl/9350. Most of the times, this is still a regular string, so let's print it like that if we can, and resort to base64 encoding if we can't. We were also wrongly always outputting the second character in the string. Change-Id: Id0e2a9d9f1ad3d2d7b554893ecd89a7e6383e9c2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9445 Autosubmit: flokli Tested-by: BuildkiteCI Reviewed-by: raitobezarius --- tvix/nix-compat/src/store_path/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tvix/nix-compat/src') diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs index 0ed6b2ba0754..e9e2978b7cc8 100644 --- a/tvix/nix-compat/src/store_path/mod.rs +++ b/tvix/nix-compat/src/store_path/mod.rs @@ -1,4 +1,5 @@ use crate::nixbase32::{self, Nixbase32DecodeError}; +use data_encoding::BASE64; use std::{fmt, path::PathBuf, str::FromStr}; use thiserror; @@ -28,7 +29,11 @@ pub enum Error { InvalidHashEncoding(Nixbase32DecodeError), #[error("Invalid length")] InvalidLength(), - #[error("Invalid name: {:?}, character at position {} ('{}') is invalid", .0, .1, .0[1])] + #[error( + "Invalid name: \"{}\", character at position {} is invalid", + std::str::from_utf8(&.0).unwrap_or(&BASE64.encode(.0)), + .1, + )] InvalidName(Vec, usize), #[error("Tried to parse an absolute path which was missing the store dir prefix.")] MissingStoreDir(), -- cgit 1.4.1