refactor(tvix/derivation): use DerivationError in Output::validate
Change-Id: I7dbd3b8ff9ef92acddde2e579fb24b8311c34d8f Reviewed-on: https://cl.tvl.fyi/c/depot/+/7852 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
		
							parent
							
								
									eebb3ce028
								
							
						
					
					
						commit
						6e7f06d942
					
				
					 4 changed files with 18 additions and 12 deletions
				
			
		| 
						 | 
					@ -13,9 +13,8 @@ pub enum DerivationError {
 | 
				
			||||||
    MoreThanOneOutputButFixed(),
 | 
					    MoreThanOneOutputButFixed(),
 | 
				
			||||||
    #[error("Invalid output name for fixed-output derivation: {0}.")]
 | 
					    #[error("Invalid output name for fixed-output derivation: {0}.")]
 | 
				
			||||||
    InvalidOutputNameForFixed(String),
 | 
					    InvalidOutputNameForFixed(String),
 | 
				
			||||||
    #[error("Unable to parse path of output {0}: {1}.")]
 | 
					    #[error("Unable to validate output {0}: {1}.")]
 | 
				
			||||||
    InvalidOutputPath(String, ParseStorePathError),
 | 
					    InvalidOutput(String, OutputError),
 | 
				
			||||||
 | 
					 | 
				
			||||||
    // input derivation
 | 
					    // input derivation
 | 
				
			||||||
    #[error("Unable to parse input derivation path {0}: {1}.")]
 | 
					    #[error("Unable to parse input derivation path {0}: {1}.")]
 | 
				
			||||||
    InvalidInputDerivationPath(String, ParseStorePathError),
 | 
					    InvalidInputDerivationPath(String, ParseStorePathError),
 | 
				
			||||||
| 
						 | 
					@ -42,3 +41,10 @@ pub enum DerivationError {
 | 
				
			||||||
    #[error("Invalid environment key {0}")]
 | 
					    #[error("Invalid environment key {0}")]
 | 
				
			||||||
    InvalidEnvironmentKey(String),
 | 
					    InvalidEnvironmentKey(String),
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Errors that can occur during the validation of a specific [Output] of a [Derviation].
 | 
				
			||||||
 | 
					#[derive(Debug, Error)]
 | 
				
			||||||
 | 
					pub enum OutputError {
 | 
				
			||||||
 | 
					    #[error("Invalid ouput path {0}: {1}")]
 | 
				
			||||||
 | 
					    InvalidOutputPath(String, ParseStorePathError),
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -12,5 +12,5 @@ mod tests;
 | 
				
			||||||
// Public API of the crate.
 | 
					// Public API of the crate.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub use derivation::Derivation;
 | 
					pub use derivation::Derivation;
 | 
				
			||||||
pub use errors::DerivationError;
 | 
					pub use errors::{DerivationError, OutputError};
 | 
				
			||||||
pub use output::{Hash, Output};
 | 
					pub use output::{Hash, Output};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,7 @@
 | 
				
			||||||
use serde::{Deserialize, Serialize};
 | 
					use serde::{Deserialize, Serialize};
 | 
				
			||||||
use tvix_store::store_path::{ParseStorePathError, StorePath};
 | 
					use tvix_store::store_path::StorePath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use crate::OutputError;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
 | 
					#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
 | 
				
			||||||
pub struct Output {
 | 
					pub struct Output {
 | 
				
			||||||
| 
						 | 
					@ -22,9 +24,10 @@ impl Output {
 | 
				
			||||||
        self.hash.is_some()
 | 
					        self.hash.is_some()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn validate(&self) -> Result<(), ParseStorePathError> {
 | 
					    pub fn validate(&self) -> Result<(), OutputError> {
 | 
				
			||||||
 | 
					        // TODO: add validation for hash, hashAlgo
 | 
				
			||||||
        if let Err(e) = StorePath::from_absolute_path(&self.path) {
 | 
					        if let Err(e) = StorePath::from_absolute_path(&self.path) {
 | 
				
			||||||
            return Err(e);
 | 
					            return Err(OutputError::InvalidOutputPath(self.path.to_string(), e));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        Ok(())
 | 
					        Ok(())
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -39,11 +39,8 @@ impl Derivation {
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if let Err(e) = output.validate() {
 | 
					            if let Err(e) = output.validate() {
 | 
				
			||||||
                return Err(DerivationError::InvalidOutputPath(
 | 
					                return Err(DerivationError::InvalidOutput(output_name.to_string(), e));
 | 
				
			||||||
                    output_name.to_string(),
 | 
					            }
 | 
				
			||||||
                    e,
 | 
					 | 
				
			||||||
                ));
 | 
					 | 
				
			||||||
            };
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Validate all input_derivations
 | 
					        // Validate all input_derivations
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue