tvix_glue/builtins/
errors.rs

1//! Contains errors that can occur during evaluation of builtins in this crate
2use nix_compat::{
3    nixhash::{self, NixHash},
4    store_path::BuildStorePathError,
5};
6use std::{path::PathBuf, rc::Rc};
7use thiserror::Error;
8
9/// Errors related to derivation construction
10#[derive(Debug, Error)]
11pub enum DerivationError {
12    #[error("an output with the name '{0}' is already defined")]
13    DuplicateOutput(String),
14    #[error("fixed-output derivations can only have the default `out`-output")]
15    ConflictingOutputTypes,
16    #[error("the environment variable '{0}' has already been set in this derivation")]
17    DuplicateEnvVar(String),
18    #[error("invalid derivation parameters: {0}")]
19    InvalidDerivation(#[from] nix_compat::derivation::DerivationError),
20    #[error("invalid output hash: {0}")]
21    InvalidOutputHash(#[from] nixhash::Error),
22    #[error("invalid output hash mode: '{0}', only 'recursive' and 'flat` are supported")]
23    InvalidOutputHashMode(String),
24}
25
26impl From<DerivationError> for tvix_eval::ErrorKind {
27    fn from(err: DerivationError) -> Self {
28        tvix_eval::ErrorKind::TvixError(Rc::new(err))
29    }
30}
31
32#[derive(Debug, Error)]
33pub enum FetcherError {
34    #[error(
35        "hash mismatch in file downloaded from TODO(url):\n  wanted: {wanted}\n     got: {got}"
36    )]
37    HashMismatch {
38        // url: Url,
39        wanted: NixHash,
40        got: NixHash,
41    },
42
43    #[error("Invalid hash type '{0}' for fetcher")]
44    InvalidHashType(&'static str),
45
46    #[error("Unable to parse URL: {0}")]
47    InvalidUrl(#[from] url::ParseError),
48
49    #[error(transparent)]
50    Io(#[from] std::io::Error),
51
52    #[error("Error calculating store path for fetcher output: {0}")]
53    StorePath(#[from] BuildStorePathError),
54}
55
56/// Errors related to `builtins.path` and `builtins.filterSource`,
57/// a.k.a. "importing" builtins.
58#[derive(Debug, Error)]
59pub enum ImportError {
60    #[error("non-file '{0}' cannot be imported in 'flat' mode")]
61    FlatImportOfNonFile(PathBuf),
62
63    #[error("hash mismatch at ingestion of '{0}', expected: '{1}', got: '{2}'")]
64    HashMismatch(PathBuf, NixHash, NixHash),
65
66    #[error("path '{}' is not absolute or invalid", .0.display())]
67    PathNotAbsoluteOrInvalid(PathBuf),
68}
69
70impl From<ImportError> for tvix_eval::ErrorKind {
71    fn from(err: ImportError) -> Self {
72        tvix_eval::ErrorKind::TvixError(Rc::new(err))
73    }
74}