From ffb134398dedcae6cd13cdf49b2cd57d43793bda Mon Sep 17 00:00:00 2001 From: Aspen Smith Date: Thu, 22 Feb 2024 16:09:28 -0500 Subject: refactor(tvix/glue): Make a single errors.rs module To pave the way for adding a new error type for builtins in this crate, move DerivationError to a new builtins::errors module. Change-Id: I65fcad63e43ed40ad39c2c6540a2ab80fdd90fd4 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11016 Tested-by: BuildkiteCI Reviewed-by: flokli Autosubmit: aspen --- tvix/glue/src/builtins/derivation_error.rs | 27 --------------------------- tvix/glue/src/builtins/errors.rs | 27 +++++++++++++++++++++++++++ tvix/glue/src/builtins/mod.rs | 5 ++--- 3 files changed, 29 insertions(+), 30 deletions(-) delete mode 100644 tvix/glue/src/builtins/derivation_error.rs create mode 100644 tvix/glue/src/builtins/errors.rs (limited to 'tvix') diff --git a/tvix/glue/src/builtins/derivation_error.rs b/tvix/glue/src/builtins/derivation_error.rs deleted file mode 100644 index 25471f0fdf48..000000000000 --- a/tvix/glue/src/builtins/derivation_error.rs +++ /dev/null @@ -1,27 +0,0 @@ -//! Contains [crate::builtins::DerivationError]. -use nix_compat::{derivation::DerivationError, nixhash}; -use std::rc::Rc; -use thiserror::Error; - -/// Errors related to derivation construction -#[derive(Debug, Error)] -pub enum Error { - #[error("an output with the name '{0}' is already defined")] - DuplicateOutput(String), - #[error("fixed-output derivations can only have the default `out`-output")] - ConflictingOutputTypes, - #[error("the environment variable '{0}' has already been set in this derivation")] - DuplicateEnvVar(String), - #[error("invalid derivation parameters: {0}")] - InvalidDerivation(DerivationError), - #[error("invalid output hash: {0}")] - InvalidOutputHash(nixhash::Error), - #[error("invalid output hash mode: '{0}', only 'recursive' and 'flat` are supported")] - InvalidOutputHashMode(String), -} - -impl From for tvix_eval::ErrorKind { - fn from(err: Error) -> Self { - tvix_eval::ErrorKind::TvixError(Rc::new(err)) - } -} diff --git a/tvix/glue/src/builtins/errors.rs b/tvix/glue/src/builtins/errors.rs new file mode 100644 index 000000000000..b606aa6a7c48 --- /dev/null +++ b/tvix/glue/src/builtins/errors.rs @@ -0,0 +1,27 @@ +//! Contains errors that can occur during evaluation of builtins in this crate +use nix_compat::nixhash; +use std::rc::Rc; +use thiserror::Error; + +/// Errors related to derivation construction +#[derive(Debug, Error)] +pub enum DerivationError { + #[error("an output with the name '{0}' is already defined")] + DuplicateOutput(String), + #[error("fixed-output derivations can only have the default `out`-output")] + ConflictingOutputTypes, + #[error("the environment variable '{0}' has already been set in this derivation")] + DuplicateEnvVar(String), + #[error("invalid derivation parameters: {0}")] + InvalidDerivation(#[from] nix_compat::derivation::DerivationError), + #[error("invalid output hash: {0}")] + InvalidOutputHash(#[from] nixhash::Error), + #[error("invalid output hash mode: '{0}', only 'recursive' and 'flat` are supported")] + InvalidOutputHashMode(String), +} + +impl From for tvix_eval::ErrorKind { + fn from(err: DerivationError) -> Self { + tvix_eval::ErrorKind::TvixError(Rc::new(err)) + } +} diff --git a/tvix/glue/src/builtins/mod.rs b/tvix/glue/src/builtins/mod.rs index a62ba192871f..c528bd46424b 100644 --- a/tvix/glue/src/builtins/mod.rs +++ b/tvix/glue/src/builtins/mod.rs @@ -5,12 +5,11 @@ use std::rc::Rc; use crate::tvix_store_io::TvixStoreIO; mod derivation; -mod derivation_error; +mod errors; mod fetchers; - mod import; -pub use derivation_error::Error as DerivationError; +pub use errors::DerivationError; /// Adds derivation-related builtins to the passed [tvix_eval::Evaluation]. /// -- cgit 1.4.1