Add name of key to key upload errors

> example | Key upload failed: Error processing key "meow": I/O Error: No such file or directory (os error 2)

Fixes #101.
This commit is contained in:
Zhaofeng Li 2022-06-24 17:34:37 -07:00
parent d37270f292
commit 0209b6dc40
3 changed files with 9 additions and 10 deletions

View file

@ -34,8 +34,8 @@ pub enum ColmenaError {
#[snafu(display("Validation error"))] #[snafu(display("Validation error"))]
ValidationError { errors: ValidationErrors }, ValidationError { errors: ValidationErrors },
#[snafu(display("Failed to upload keys: {}", error))] #[snafu(display("Error processing key \"{}\": {}", name, error))]
KeyError { error: key::KeyError }, KeyError { name: String, error: key::KeyError },
#[snafu(display("Store path {:?} is not a derivation", store_path))] #[snafu(display("Store path {:?} is not a derivation", store_path))]
NotADerivation { store_path: StorePath }, NotADerivation { store_path: StorePath },
@ -77,12 +77,6 @@ impl From<std::io::Error> for ColmenaError {
} }
} }
impl From<key::KeyError> for ColmenaError {
fn from(error: key::KeyError) -> Self {
Self::KeyError { error }
}
}
impl From<ValidationErrors> for ColmenaError { impl From<ValidationErrors> for ColmenaError {
fn from(errors: ValidationErrors) -> Self { fn from(errors: ValidationErrors) -> Self {
Self::ValidationError { errors } Self::ValidationError { errors }

View file

@ -12,7 +12,7 @@ use shell_escape::unix::escape;
use tokio::io::{AsyncWriteExt, BufReader}; use tokio::io::{AsyncWriteExt, BufReader};
use tokio::process::Child; use tokio::process::Child;
use crate::error::ColmenaResult; use crate::error::{ColmenaError, ColmenaResult};
use crate::job::JobHandle; use crate::job::JobHandle;
use crate::nix::Key; use crate::nix::Key;
use crate::util::capture_stream; use crate::util::capture_stream;
@ -32,7 +32,11 @@ pub fn generate_script<'a>(key: &'a Key, destination: &'a Path, require_ownershi
} }
pub async fn feed_uploader(mut uploader: Child, key: &Key, job: Option<JobHandle>) -> ColmenaResult<()> { pub async fn feed_uploader(mut uploader: Child, key: &Key, job: Option<JobHandle>) -> ColmenaResult<()> {
let mut reader = key.reader().await?; let mut reader = key.reader().await
.map_err(|error| ColmenaError::KeyError {
name: key.name().to_owned(),
error,
})?;
let mut stdin = uploader.stdin.take().unwrap(); let mut stdin = uploader.stdin.take().unwrap();
tokio::io::copy(reader.as_mut(), &mut stdin).await?; tokio::io::copy(reader.as_mut(), &mut stdin).await?;

View file

@ -148,6 +148,7 @@ impl Key {
} }
} }
pub fn name(&self) -> &str { &self.name }
pub fn path(&self) -> &Path { &self.path } pub fn path(&self) -> &Path { &self.path }
pub fn user(&self) -> &str { &self.user } pub fn user(&self) -> &str { &self.user }
pub fn group(&self) -> &str { &self.group } pub fn group(&self) -> &str { &self.group }