snix/tvix/nix-compat/src/derivation/errors.rs
John Ericson 26c68f8e89 refactor(nix-compat): Properly encapsulate store path construction
Before there was code scattered about (e.g. text hashing module and
derivation output computation) constructing store paths from low level
building blocks --- there was some duplication and it was easy to make
nonsense store paths.

Now, we have roughly the same "safe-ish" ways of constructing them as
C++ Nix, and only those are exposed:

- Make text hashed content-addressed store paths

- Make other content-addressed store paths

- Make input-addressed fixed output hashes

Change-Id: I122a3ee0802b4f45ae386306b95b698991be89c8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8411
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
2023-04-09 15:12:21 +00:00

59 lines
2.2 KiB
Rust

use crate::{nixbase32::Nixbase32DecodeError, store_path};
use thiserror::Error;
/// Errors that can occur during the validation of Derivation structs.
#[derive(Debug, Error, PartialEq)]
pub enum DerivationError {
// outputs
#[error("no outputs defined")]
NoOutputs(),
#[error("invalid output name: {0}")]
InvalidOutputName(String),
#[error("encountered fixed-output derivation, but more than 1 output in total")]
MoreThanOneOutputButFixed(),
#[error("invalid output name for fixed-output derivation: {0}")]
InvalidOutputNameForFixed(String),
#[error("unable to validate output {0}: {1}")]
InvalidOutput(String, OutputError),
#[error("unable to validate output {0}: {1}")]
InvalidOutputDerivationPath(String, store_path::BuildStorePathError),
// input derivation
#[error("unable to parse input derivation path {0}: {1}")]
InvalidInputDerivationPath(String, store_path::Error),
#[error("input derivation {0} doesn't end with .drv")]
InvalidInputDerivationPrefix(String),
#[error("input derivation {0} output names are empty")]
EmptyInputDerivationOutputNames(String),
#[error("input derivation {0} output name {1} is invalid")]
InvalidInputDerivationOutputName(String, String),
// input sources
#[error("unable to parse input sources path {0}: {1}")]
InvalidInputSourcesPath(String, store_path::Error),
// platform
#[error("invalid platform field: {0}")]
InvalidPlatform(String),
// builder
#[error("invalid builder field: {0}")]
InvalidBuilder(String),
// environment
#[error("invalid environment key {0}")]
InvalidEnvironmentKey(String),
}
/// Errors that can occur during the validation of a specific
// [crate::derivation::Output] of a [crate::derivation::Derviation].
#[derive(Debug, Error, PartialEq)]
pub enum OutputError {
#[error("Invalid output path {0}: {1}")]
InvalidOutputPath(String, store_path::Error),
#[error("Invalid hash encoding: {0}")]
InvalidHashEncoding(String, Nixbase32DecodeError),
#[error("Invalid hash algo: {0}")]
InvalidHashAlgo(String),
#[error("Invalid Digest size {0} for algo {1}")]
InvalidDigestSizeForAlgo(usize, String),
}