mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-23 00:44:55 +03:00
Use PathBuf in FileReadAccess error.
This commit is contained in:
parent
8c4bf79c80
commit
74d76db2a2
@ -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!(
|
||||
|
@ -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 } => {
|
||||
|
Loading…
Reference in New Issue
Block a user