From e003ac8f1ef5c4248fbf0c61a3132624f1b401d2 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Fri, 18 Aug 2023 16:08:25 -0500 Subject: [PATCH] fix(cli): Improve error on missing config --- crates/typos-cli/src/config.rs | 8 +++++++- crates/typos-cli/tests/cmd/missing-config.toml | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/typos-cli/src/config.rs b/crates/typos-cli/src/config.rs index 5eb5d5c..67701a9 100644 --- a/crates/typos-cli/src/config.rs +++ b/crates/typos-cli/src/config.rs @@ -31,7 +31,13 @@ impl Config { } pub fn from_file(path: &std::path::Path) -> Result { - let s = std::fs::read_to_string(path)?; + let s = std::fs::read_to_string(path).map_err(|err| { + let kind = err.kind(); + std::io::Error::new( + kind, + format!("could not read config at `{}`", path.display()), + ) + })?; Self::from_toml(&s) } diff --git a/crates/typos-cli/tests/cmd/missing-config.toml b/crates/typos-cli/tests/cmd/missing-config.toml index fa88e3b..e3232b6 100644 --- a/crates/typos-cli/tests/cmd/missing-config.toml +++ b/crates/typos-cli/tests/cmd/missing-config.toml @@ -4,5 +4,5 @@ status.code = 78 stdin = "" # stdout doesn't have stable order stderr = """ -No such file or directory (os error 2) +could not read config at `foo.toml` """