Skip to content

Commit 4bff4be

Browse files
committed
Clarify error messages
1 parent 1465b92 commit 4bff4be

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

src/lib.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,22 @@ pub fn test_load_dll(dll_path: std::path::PathBuf) -> ah::Result<libtxc::Module>
3838
unsafe { libtxc::Module::load(dll_path.clone()).map_err(Into::into) }
3939
}
4040

41-
pub fn test_write_log_dir(mut log_dir: std::path::PathBuf) -> ah::Result<()> {
42-
use std::fs;
43-
// Create and delete a dummy file at `log_dir` to ensure the path do exists and is writable.
44-
fs::create_dir_all(log_dir.clone())?;
45-
log_dir.push("temp.file");
46-
fs::write(log_dir.clone(), "temp")?;
47-
fs::remove_file(log_dir).map_err(Into::into)
41+
pub fn test_write_log_dir(mut dir: std::path::PathBuf) -> ah::Result<()> {
42+
if !dir.exists() {
43+
ah::bail!("Путь {dir:?} не существует");
44+
}
45+
if !dir.is_dir() {
46+
ah::bail!("{dir:?} не является директорией");
47+
}
48+
if dir.metadata().map_err(Into::<ah::Error>::into)?.permissions().readonly() {
49+
ah::bail!("{dir:?} недоступна для записи");
50+
}
51+
52+
dir.push("temp");
53+
std::fs::write(dir.clone(), "temp.file")?;
54+
std::fs::remove_file(dir)?;
55+
56+
Ok(())
4857
}
4958

5059
pub fn txc_log_level() -> i32 {
@@ -67,7 +76,7 @@ pub fn read_handler_params() -> ah::Result<(TcpStream, PathBuf, PathBuf)> {
6776

6877
match env::args().collect::<Vec<String>>().as_slice() {
6978
[.., log_dir, dll_path] => Ok((con, log_dir.into(), dll_path.into())),
70-
_ => ah::bail!("the 'impossible' happened"), /*unreachable*/
79+
_ => unreachable!("unexpected number of arguments"),
7180
}
7281
}
7382

0 commit comments

Comments
 (0)