Use PathBuf in FileReadAccess error.

This commit is contained in:
jcamiel 2024-03-13 17:18:37 +01:00 committed by hurl-bot
parent 8c4bf79c80
commit 74d76db2a2
No known key found for this signature in database
GPG Key ID: 1283A2B4A0DCAF8D
2 changed files with 11 additions and 6 deletions

View File

@ -80,10 +80,13 @@ pub fn eval_file(
return Err(Error::new(filename.source_info, inner, false));
}
let resolved_file = context_dir.get_path(&file);
let inner = RunnerError::FileReadAccess { file };
match std::fs::read(resolved_file) {
Ok(value) => Ok(value),
Err(_) => Err(Error::new(filename.source_info, inner, false)),
Err(_) => {
let path = PathBuf::from(&file);
let inner = RunnerError::FileReadAccess { path };
Err(Error::new(filename.source_info, inner, false))
}
}
}
@ -156,7 +159,7 @@ mod tests {
assert_eq!(
error.inner,
RunnerError::FileReadAccess {
file: "data.bin".to_string()
path: PathBuf::from("data.bin")
}
);
assert_eq!(

View File

@ -65,7 +65,7 @@ pub enum RunnerError {
CouldNotParseResponse,
CouldNotUncompressResponse(String),
FileReadAccess {
file: String,
path: PathBuf,
},
// I/O write error on a path
FileWriteAccess {
@ -188,7 +188,9 @@ impl hurl_core::error::Error for Error {
RunnerError::CouldNotUncompressResponse(algorithm) => {
format!("could not uncompress response with {algorithm}")
}
RunnerError::FileReadAccess { file } => format!("file {file} can not be read"),
RunnerError::FileReadAccess { path } => {
format!("file {} can not be read", path.to_string_lossy())
}
RunnerError::FileWriteAccess { file, error } => {
format!("{file} can not be written ({error})")
}
@ -239,7 +241,7 @@ impl hurl_core::error::Error for Error {
RunnerError::UnauthorizedFileAccess { path } => {
format!(
"unauthorized access to file {}, check --file-root option",
path.to_str().unwrap()
path.to_string_lossy()
)
}
RunnerError::UnrenderableVariable { name, value } => {