about summary refs log tree commit diff
path: root/tvix/glue/src/builtins/errors.rs
blob: c753a125e0308b225963aa02ea58bd96adc2b35b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Contains errors that can occur during evaluation of builtins in this crate
use nix_compat::{
    nixhash::{self, NixHash},
    store_path::BuildStorePathError,
};
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<DerivationError> for tvix_eval::ErrorKind {
    fn from(err: DerivationError) -> Self {
        tvix_eval::ErrorKind::TvixError(Rc::new(err))
    }
}

#[derive(Debug, Error)]
pub enum FetcherError {
    #[error("hash mismatch in file downloaded from {url}:\n  wanted: {wanted}\n     got: {got}")]
    HashMismatch {
        url: String,
        wanted: NixHash,
        got: NixHash,
    },

    #[error("Invalid hash type '{0}' for fetcher")]
    InvalidHashType(&'static str),

    #[error("Error in store path for fetcher output: {0}")]
    StorePath(#[from] BuildStorePathError),

    #[error(transparent)]
    Http(#[from] reqwest::Error),
}

impl From<FetcherError> for tvix_eval::ErrorKind {
    fn from(err: FetcherError) -> Self {
        tvix_eval::ErrorKind::TvixError(Rc::new(err))
    }
}