about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authoredef <edef@edef.eu>2023-10-10T10·03+0000
committeredef <edef@edef.eu>2023-10-10T16·58+0000
commitbb54e04c1bf443772414ba1c21d072b1fce83506 (patch)
treeae4cb5bfb2e757087e92ac64424f9c432e081c49 /tvix
parentda648b4707fb1d8fd6a9679669d2eb36a5f0832c (diff)
fix(tvix/nix-compat): clean up the debug assertions a bit r/6766
Consistent error messages, and slightly nicer code layout. We avoid
printing the input data, since we primarily want to point out the
specific violated invariant. In the one place where we do want to,
we use BStr's Debug implementation, since byte slices don't print
nicely.

Change-Id: I3a9a0c37be270ea5f16cf124922c254608fb849e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9617
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
Autosubmit: edef <edef@edef.eu>
Diffstat (limited to 'tvix')
-rw-r--r--tvix/nix-compat/src/nar/writer/mod.rs23
1 files changed, 11 insertions, 12 deletions
diff --git a/tvix/nix-compat/src/nar/writer/mod.rs b/tvix/nix-compat/src/nar/writer/mod.rs
index f73d323e3820..9abc2510d149 100644
--- a/tvix/nix-compat/src/nar/writer/mod.rs
+++ b/tvix/nix-compat/src/nar/writer/mod.rs
@@ -28,6 +28,7 @@
 //! # Ok::<(), std::io::Error>(())
 //! ```
 
+use bstr::ByteSlice;
 use std::io::{
     self, BufRead,
     ErrorKind::{InvalidInput, UnexpectedEof},
@@ -73,11 +74,8 @@ impl<'a, 'w> Node<'a, 'w> {
             "target.len() > {}",
             wire::MAX_TARGET_LEN
         );
-        debug_assert!(
-            !target.contains(&b'\0'),
-            "invalid target characters: {target:?}"
-        );
-        debug_assert!(!target.is_empty(), "empty target");
+        debug_assert!(!target.is_empty(), "target is empty");
+        debug_assert!(!target.contains(&0), "target contains null byte");
 
         self.write(&wire::TOK_SYM)?;
         self.write(&target.len().to_le_bytes())?;
@@ -176,12 +174,11 @@ impl<'a, 'w> Directory<'a, 'w> {
             "name.len() > {}",
             wire::MAX_NAME_LEN
         );
-        debug_assert!(name != b"", "name may not be empty");
-        debug_assert!(name != b".", "invalid name: {name:?}");
-        debug_assert!(name != b"..", "invalid name: {name:?}");
-
-        debug_assert!(!name.contains(&b'/'), "invalid name characters: {name:?}");
-        debug_assert!(!name.contains(&b'\0'), "invalid name characters: {name:?}");
+        debug_assert!(!name.is_empty(), "name is empty");
+        debug_assert!(!name.contains(&0), "name contains null byte");
+        debug_assert!(!name.contains(&b'/'), "name contains {:?}", '/');
+        debug_assert!(name != b".", "name == {:?}", ".");
+        debug_assert!(name != b"..", "name == {:?}", "..");
 
         match self.prev_name {
             None => {
@@ -192,7 +189,9 @@ impl<'a, 'w> Directory<'a, 'w> {
                 {
                     assert!(
                         &**_prev_name < name,
-                        "misordered names: {_prev_name:?} >= {name:?}"
+                        "misordered names: {:?} >= {:?}",
+                        _prev_name.as_bstr(),
+                        name.as_bstr()
                     );
                     _prev_name.clear();
                     _prev_name.extend_from_slice(name);