From e1986e45701972d4630284f095aec6c6bf4178ac Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Thu, 9 Feb 2023 18:08:53 +0100 Subject: [PATCH] cli: Add better error for test not found --- radicle-cli/tests/framework/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/radicle-cli/tests/framework/mod.rs b/radicle-cli/tests/framework/mod.rs index 47f81995..cd5fa4e3 100644 --- a/radicle-cli/tests/framework/mod.rs +++ b/radicle-cli/tests/framework/mod.rs @@ -15,6 +15,8 @@ const ERROR_PREFIX: &str = "=="; pub enum Error { #[error("parsing failed")] Parse, + #[error("test file not found: {0:?}")] + TestNotFound(PathBuf), #[error("i/o: {0}")] Io(#[from] io::Error), #[error("snapbox: {0}")] @@ -92,7 +94,14 @@ impl TestFormula { } pub fn file(&mut self, path: impl AsRef) -> Result<&mut Self, Error> { - let contents = fs::read(path)?; + let path = path.as_ref(); + let contents = match fs::read(path) { + Ok(bytes) => bytes, + Err(err) if err.kind() == io::ErrorKind::NotFound => { + return Err(Error::TestNotFound(path.to_path_buf())); + } + Err(err) => return Err(err.into()), + }; self.read(io::Cursor::new(contents)) }