From 930edb69d7447f0cbe9149d01dcf9fa8443518c8 Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 10 Oct 2023 22:06:45 +0000 Subject: fix(tvix/castore): use bstr for formatting names in errors Much friendlier than either Base64 or raw byte slices. Change-Id: I9b4cdd57c83ddc76c0be8103da4320207657a72b Reviewed-on: https://cl.tvl.fyi/c/depot/+/9622 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/Cargo.lock | 1 + tvix/Cargo.nix | 4 ++++ tvix/castore/Cargo.toml | 1 + tvix/castore/src/proto/mod.rs | 8 ++++---- 4 files changed, 10 insertions(+), 4 deletions(-) (limited to 'tvix') diff --git a/tvix/Cargo.lock b/tvix/Cargo.lock index 23eba3000513..2f4baae86188 100644 --- a/tvix/Cargo.lock +++ b/tvix/Cargo.lock @@ -2713,6 +2713,7 @@ version = "0.1.0" dependencies = [ "async-stream", "blake3", + "bstr", "bytes", "data-encoding", "futures", diff --git a/tvix/Cargo.nix b/tvix/Cargo.nix index 548eef65c1cb..24387793daf7 100644 --- a/tvix/Cargo.nix +++ b/tvix/Cargo.nix @@ -8116,6 +8116,10 @@ rec { packageId = "blake3"; features = [ "rayon" "std" ]; } + { + name = "bstr"; + packageId = "bstr"; + } { name = "bytes"; packageId = "bytes"; diff --git a/tvix/castore/Cargo.toml b/tvix/castore/Cargo.toml index 4dab3bfa4469..69da905a8777 100644 --- a/tvix/castore/Cargo.toml +++ b/tvix/castore/Cargo.toml @@ -22,6 +22,7 @@ tower = "0.4.13" tracing = "0.1.37" url = "2.4.0" walkdir = "2.4.0" +bstr = "1.6.0" [dependencies.tonic-reflection] optional = true diff --git a/tvix/castore/src/proto/mod.rs b/tvix/castore/src/proto/mod.rs index ba3fcbceb14d..66ed5b0f1f89 100644 --- a/tvix/castore/src/proto/mod.rs +++ b/tvix/castore/src/proto/mod.rs @@ -1,6 +1,6 @@ #![allow(clippy::derive_partial_eq_without_eq, non_snake_case)] // https://github.com/hyperium/tonic/issues/1056 -use data_encoding::BASE64; +use bstr::ByteSlice; use std::{collections::HashSet, iter::Peekable}; use thiserror::Error; @@ -29,13 +29,13 @@ mod tests; #[derive(Debug, PartialEq, Eq, Error)] pub enum ValidateDirectoryError { /// Elements are not in sorted order - #[error("{} is not sorted", std::str::from_utf8(.0).unwrap_or(&BASE64.encode(.0)))] + #[error("{:?} is not sorted", .0.as_bstr())] WrongSorting(Vec), /// Multiple elements with the same name encountered - #[error("{0:?} is a duplicate name")] + #[error("{:?} is a duplicate name", .0.as_bstr())] DuplicateName(Vec), /// Invalid name encountered - #[error("Invalid name in {0:?}")] + #[error("Invalid name in {:?}", .0.as_bstr())] InvalidName(Vec), /// Invalid digest length encountered #[error("Invalid Digest length: {0}")] -- cgit 1.4.1