about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBob van der Linden <bobvanderlinden@gmail.com>2024-10-30T22·37+0100
committerBob van der Linden <bobvanderlinden@gmail.com>2024-11-02T19·51+0000
commit37835634e8009381d6747ab01cbfc4134d637654 (patch)
tree13e15ce55883b1e144fdde45fec3e4ca8f324b20
parent05cb6e9e350463573857a02b8c5a1f5496500c8f (diff)
feat(tvix/glue): use InvalidHash for builtins.path r/8882
Previously such errors showed up as:

error[E006]: expected value of type 'sha256', but found a 'not a sha256'

Now they show up as:

error[E041]: Invalid hash: invalid encoded digest length '31' for algo
sha256

This is consistent with the errors of `builtins.fetchurl`.

Change-Id: Id11b26fc7951778640cc4e41b3bf23203eaf07df
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12719
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
-rw-r--r--tvix/glue/src/builtins/import.rs11
1 files changed, 1 insertions, 10 deletions
diff --git a/tvix/glue/src/builtins/import.rs b/tvix/glue/src/builtins/import.rs
index 5f495dcc623b..83b91165c09e 100644
--- a/tvix/glue/src/builtins/import.rs
+++ b/tvix/glue/src/builtins/import.rs
@@ -353,16 +353,7 @@ mod import_builtins {
                     match nix_compat::nixhash::from_str(expected.to_str()?, Some("sha256")) {
                         Ok(NixHash::Sha256(digest)) => Ok(digest),
                         Ok(_) => unreachable!(),
-                        Err(_e) => {
-                            // TODO: a better error would be nice, we use
-                            // DerivationError::InvalidOutputHash usually for derivation construction.
-                            // This is not a derivation construction, should we move it outside and
-                            // generalize?
-                            Err(ErrorKind::TypeError {
-                                expected: "sha256",
-                                actual: "not a sha256",
-                            })
-                        }
+                        Err(e) => Err(ErrorKind::InvalidHash(e.to_string())),
                     }
                 })
             })