diff options
author | Bob van der Linden <bobvanderlinden@gmail.com> | 2024-10-30T21·36+0100 |
---|---|---|
committer | Bob van der Linden <bobvanderlinden@gmail.com> | 2024-11-02T19·51+0000 |
commit | 05cb6e9e350463573857a02b8c5a1f5496500c8f (patch) | |
tree | d7dd6492e838ee2ad8319a308084859ba40b60ad | |
parent | aecf0641a4917994e58e0fe7a9cfecb596f0c4f6 (diff) |
feat(tvix/eval): introduce ErrorKind::InvalidHash r/8881
The nixhash errors were wrapped in a generic TvixError. Now it has its own TvixError with unique error code. The nixhash error is passed along as a string. The errors looked like: error[E997]: invalid encoded digest length '51' for algo sha256 Now they look like: error[E041]: Invalid hash: invalid encoded digest length '51' for algo sha256 Change-Id: I5c420815538ba4c6567c95f5d44d60c4d48f43fd Reviewed-on: https://cl.tvl.fyi/c/depot/+/12718 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
-rw-r--r-- | tvix/eval/src/errors.rs | 5 | ||||
-rw-r--r-- | tvix/glue/src/builtins/fetchers.rs | 3 |
2 files changed, 6 insertions, 2 deletions
diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index 9c3383fc5d94..9b5384690e46 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -236,6 +236,9 @@ to a missing value in the attribute set(s) included via `with`."# #[error("Invalid UTF-8 in string")] Utf8, + #[error("Invalid hash: {0}")] + InvalidHash(String), + /// Variant for errors that bubble up to eval from other Tvix /// components. #[error("{0}")] @@ -676,6 +679,7 @@ impl Error { | ErrorKind::NotImplemented(_) | ErrorKind::WithContext { .. } | ErrorKind::UnknownHashType(_) + | ErrorKind::InvalidHash(_) | ErrorKind::CatchableError(_) => return None, }; @@ -722,6 +726,7 @@ impl Error { ErrorKind::Utf8 => "E038", ErrorKind::UnknownHashType(_) => "E039", ErrorKind::UnexpectedArgumentBuiltin { .. } => "E040", + ErrorKind::InvalidHash(_) => "E041", // Special error code for errors from other Tvix // components. We may want to introduce a code namespacing diff --git a/tvix/glue/src/builtins/fetchers.rs b/tvix/glue/src/builtins/fetchers.rs index 1ad43b383353..2d9b30586703 100644 --- a/tvix/glue/src/builtins/fetchers.rs +++ b/tvix/glue/src/builtins/fetchers.rs @@ -73,8 +73,7 @@ async fn extract_fetch_args( let sha256 = match sha256_str { Some(sha256_str) => { let nixhash = nixhash::from_str(&sha256_str, Some("sha256")) - // TODO: DerivationError::InvalidOutputHash should be moved to ErrorKind::InvalidHash and used here instead - .map_err(|e| ErrorKind::TvixError(Rc::new(e)))?; + .map_err(|e| ErrorKind::InvalidHash(e.to_string()))?; Some(nixhash.digest_as_bytes().try_into().expect("is sha256")) } |