From 51b8571c48168435c892cb58e9ad62f7c979e4d5 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 17 Sep 2023 14:59:35 +0300 Subject: [PATCH] feat(tvix/store): improve error message formatting WrongSorting(Vec) actually encodes the name of a node, so if we can, we want this to display it as a string (and fall back to the base64 encoding if we can't). Before: > rpc error: code = InvalidArgument desc = directory b3:yfwNlpPm8MkrRvshGHfgMtKLoSDtX2pKliVuVWmUt5g= failed validation: [108, 111, 99, 97, 108, 101] is not sorted After: > rpc error: code = InvalidArgument desc = directory b3:yfwNlpPm8MkrRvshGHfgMtKLoSDtX2pKliVuVWmUt5g= failed validation: locale is not sorted Change-Id: I68420c53a89cb1aa96e4bdce414366cebcb7915f Reviewed-on: https://cl.tvl.fyi/c/depot/+/9350 Tested-by: BuildkiteCI Reviewed-by: Connor Brewster Reviewed-by: raitobezarius --- tvix/store/src/proto/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tvix/store/src/proto/mod.rs b/tvix/store/src/proto/mod.rs index 9dea99fed..044769ce5 100644 --- a/tvix/store/src/proto/mod.rs +++ b/tvix/store/src/proto/mod.rs @@ -1,5 +1,6 @@ #![allow(clippy::derive_partial_eq_without_eq, non_snake_case)] // https://github.com/hyperium/tonic/issues/1056 +use data_encoding::BASE64; use std::{collections::HashSet, iter::Peekable}; use thiserror::Error; @@ -34,7 +35,7 @@ mod tests; #[derive(Debug, PartialEq, Eq, Error)] pub enum ValidateDirectoryError { /// Elements are not in sorted order - #[error("{0:?} is not sorted")] + #[error("{} is not sorted", std::str::from_utf8(.0).unwrap_or(&BASE64.encode(.0)))] WrongSorting(Vec), /// Multiple elements with the same name encountered #[error("{0:?} is a duplicate name")]