2023-01-16 13:27:33 +03:00
|
|
|
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),
|
2023-01-23 01:28:27 +03:00
|
|
|
InvalidOutputHashMode(String),
|
2023-01-16 13:27:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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}"),
|
2023-01-23 01:28:27 +03:00
|
|
|
|
|
|
|
Error::InvalidOutputHashMode(mode) => write!(
|
|
|
|
f,
|
|
|
|
"invalid output hash mode: '{mode}', only 'recursive' and 'flat` are supported"
|
|
|
|
),
|
2023-01-16 13:27:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl error::Error for Error {
|
|
|
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Error> for tvix_eval::ErrorKind {
|
|
|
|
fn from(err: Error) -> Self {
|
|
|
|
tvix_eval::ErrorKind::TvixError(Rc::new(err))
|
|
|
|
}
|
|
|
|
}
|