Skip to content

Commit 9832a72

Browse files
committed
Adjust error wording when loading missing files
```shell $ SSL_CERT_FILE="notexist" target/debug/examples/google thread 'main' panicked at examples/google.rs:7:58: could not load platform certs: Custom { kind: NotFound, error: "could not load certs from dir notexist: No such file or directory (os error 2)" } ``` Note "from dir notexist". In this case `path.is_file()` is false (because it doesn't exist) but that doesn't imply it was being read as a directory.
1 parent 98612b4 commit 9832a72

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ impl CertPaths {
159159

160160
let mut certs = match &self.file {
161161
Some(cert_file) => {
162-
load_pem_certs(cert_file).map_err(|err| Self::load_err(cert_file, err))?
162+
load_pem_certs(cert_file).map_err(|err| Self::load_err(cert_file, "file", err))?
163163
}
164164
None => Vec::new(),
165165
};
166166

167167
if let Some(cert_dir) = &self.dir {
168168
certs.append(
169169
&mut load_pem_certs_from_dir(cert_dir)
170-
.map_err(|err| Self::load_err(cert_dir, err))?,
170+
.map_err(|err| Self::load_err(cert_dir, "dir", err))?,
171171
);
172172
}
173173

@@ -177,14 +177,10 @@ impl CertPaths {
177177
Ok(Some(certs))
178178
}
179179

180-
fn load_err(path: &Path, err: Error) -> Error {
180+
fn load_err(path: &Path, typ: &str, err: Error) -> Error {
181181
Error::new(
182182
err.kind(),
183-
format!(
184-
"could not load certs from {} {}: {err}",
185-
if path.is_file() { "file" } else { "dir" },
186-
path.display()
187-
),
183+
format!("could not load certs from {typ} {}: {err}", path.display()),
188184
)
189185
}
190186
}

0 commit comments

Comments
 (0)