From 259faea2b229edd8f2e31d0903b5fd185036b4a4 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 16 Jan 2023 13:27:33 +0300 Subject: feat(tvix/cli): add `errors` module with drv construction errors These will be threaded through to eval through the new `TvixError` variant. Change-Id: Ia0d3f8710dcf26bb95015cd2a6a2b2911f06343f Reviewed-on: https://cl.tvl.fyi/c/depot/+/7842 Reviewed-by: flokli Tested-by: BuildkiteCI --- tvix/cli/src/errors.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ tvix/cli/src/main.rs | 1 + 2 files changed, 50 insertions(+) create mode 100644 tvix/cli/src/errors.rs (limited to 'tvix/cli/src') diff --git a/tvix/cli/src/errors.rs b/tvix/cli/src/errors.rs new file mode 100644 index 000000000000..8eaaef1579aa --- /dev/null +++ b/tvix/cli/src/errors.rs @@ -0,0 +1,49 @@ +use std::{error, fmt::Display, rc::Rc}; +use tvix_derivation::DerivationError; + +#[derive(Debug)] +pub enum Error { + // Errors related to derivation construction + DuplicateOutput(String), + ConflictingOutputTypes, + DuplicateEnvVar(String), + ShadowedOutput(String), + InvalidDerivation(DerivationError), +} + +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Error::DuplicateOutput(name) => { + write!(f, "an output with the name '{name}' is already defined") + } + + Error::ConflictingOutputTypes => write!( + f, + "fixed-output derivations can only have the default `out`-output" + ), + + Error::DuplicateEnvVar(name) => write!( + f, + "the environment variable '{name}' has already been set in this derivation" + ), + Error::ShadowedOutput(name) => write!( + f, + "the environment variable '{name}' shadows the name of an output" + ), + Error::InvalidDerivation(error) => write!(f, "invalid derivation parameters: {error}"), + } + } +} + +impl error::Error for Error { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + None + } +} + +impl From for tvix_eval::ErrorKind { + fn from(err: Error) -> Self { + tvix_eval::ErrorKind::TvixError(Rc::new(err)) + } +} diff --git a/tvix/cli/src/main.rs b/tvix/cli/src/main.rs index 242cece9ecd2..6757044750fe 100644 --- a/tvix/cli/src/main.rs +++ b/tvix/cli/src/main.rs @@ -1,3 +1,4 @@ +mod errors; mod known_paths; mod nix_compat; mod refscan; -- cgit 1.4.1