Skip to main content

snix_glue/builtins/
errors.rs

1//! Contains errors that can occur during evaluation of builtins in this crate
2use nix_compat::{derivation::OutputName, nixhash::NixHash};
3use std::{path::PathBuf, sync::Arc};
4use thiserror::Error;
5
6/// Errors related to derivation construction
7#[derive(Debug, Error)]
8pub enum DerivationError {
9    #[error("an output with the name '{0}' is already defined")]
10    DuplicateOutput(OutputName),
11    #[error("fixed-output derivations can only have the default `out`-output")]
12    ConflictingOutputTypes,
13    #[error("the environment variable '{0}' has already been set in this derivation")]
14    DuplicateEnvVar(String),
15    #[error(
16        "Cannot have an environment variable named '__json'. This key is reserved for encoding structured attrs"
17    )]
18    StructuredAttrsJsonKeyPresent,
19    #[error("invalid derivation parameters: {0}")]
20    InvalidDerivation(#[from] nix_compat::derivation::DerivationError),
21}
22
23impl From<DerivationError> for snix_eval::ErrorKind {
24    fn from(err: DerivationError) -> Self {
25        snix_eval::ErrorKind::SnixError(Arc::from(err))
26    }
27}
28
29/// Errors related to `builtins.path` and `builtins.filterSource`,
30/// a.k.a. "importing" builtins.
31#[derive(Debug, Error)]
32pub enum ImportError {
33    #[error("non-file '{0}' cannot be imported in 'flat' mode")]
34    FlatImportOfNonFile(PathBuf),
35
36    #[error("hash mismatch at ingestion of '{0}', expected: '{1}', got: '{2}'")]
37    HashMismatch(PathBuf, NixHash, NixHash),
38
39    #[error("path '{}' is not absolute or invalid", .0.display())]
40    PathNotAbsoluteOrInvalid(PathBuf),
41}
42
43impl From<ImportError> for snix_eval::ErrorKind {
44    fn from(err: ImportError) -> Self {
45        snix_eval::ErrorKind::SnixError(Arc::from(err))
46    }
47}