snix_glue/builtins/
errors.rs1use nix_compat::{
3 nixhash::{self, NixHash},
4 store_path::BuildStorePathError,
5};
6use reqwest::Url;
7use snix_castore::import;
8use std::{path::PathBuf, sync::Arc};
9use thiserror::Error;
10
11#[derive(Debug, Error)]
13pub enum DerivationError {
14 #[error("an output with the name '{0}' is already defined")]
15 DuplicateOutput(String),
16 #[error("fixed-output derivations can only have the default `out`-output")]
17 ConflictingOutputTypes,
18 #[error("the environment variable '{0}' has already been set in this derivation")]
19 DuplicateEnvVar(String),
20 #[error("invalid derivation parameters: {0}")]
21 InvalidDerivation(#[from] nix_compat::derivation::DerivationError),
22 #[error("invalid output hash: {0}")]
23 InvalidOutputHash(#[from] nixhash::Error),
24 #[error("invalid output hash mode: '{0}', only 'recursive' and 'flat` are supported")]
25 InvalidOutputHashMode(String),
26 #[error(
27 "Cannot have an environment variable named '__json'. This key is reserved for encoding structured attrs"
28 )]
29 StructuredAttrsJsonKeyPresent,
30}
31
32impl From<DerivationError> for snix_eval::ErrorKind {
33 fn from(err: DerivationError) -> Self {
34 snix_eval::ErrorKind::SnixError(Arc::from(err))
35 }
36}
37
38#[derive(Debug, Error)]
39pub enum FetcherError {
40 #[error("hash mismatch in file downloaded from {url}:\n wanted: {wanted}\n got: {got}")]
41 HashMismatch {
42 url: Url,
43 wanted: NixHash,
44 got: NixHash,
45 },
46
47 #[error("Invalid hash type '{0}' for fetcher")]
48 InvalidHashType(&'static str),
49
50 #[error("Unable to parse URL: {0}")]
51 InvalidUrl(#[from] url::ParseError),
52
53 #[error(transparent)]
54 Http(#[from] reqwest::Error),
55
56 #[error(transparent)]
57 Io(#[from] std::io::Error),
58
59 #[error(transparent)]
60 Import(#[from] snix_castore::import::IngestionError<import::archive::Error>),
61
62 #[error("Error calculating store path for fetcher output: {0}")]
63 StorePath(#[from] BuildStorePathError),
64}
65
66#[derive(Debug, Error)]
69pub enum ImportError {
70 #[error("non-file '{0}' cannot be imported in 'flat' mode")]
71 FlatImportOfNonFile(PathBuf),
72
73 #[error("hash mismatch at ingestion of '{0}', expected: '{1}', got: '{2}'")]
74 HashMismatch(PathBuf, NixHash, NixHash),
75
76 #[error("path '{}' is not absolute or invalid", .0.display())]
77 PathNotAbsoluteOrInvalid(PathBuf),
78}
79
80impl From<ImportError> for snix_eval::ErrorKind {
81 fn from(err: ImportError) -> Self {
82 snix_eval::ErrorKind::SnixError(Arc::from(err))
83 }
84}