Skip to content

Commit

Permalink
Map errors
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeiPatiakin committed Feb 5, 2025
1 parent 6bb590a commit beb0edb
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions core/src/services/fs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,19 @@ impl Access for FsBackend {
let f = open_options
.open(tmp_path.as_ref().unwrap_or(&target_path))
.await
.map_err(new_std_io_error)?;
.map_err(|e| {
match e.kind() {
std::io::ErrorKind::AlreadyExists => {
// Map io AlreadyExists to opendal ConditionNotMatch
Error::new(
ErrorKind::ConditionNotMatch,
ErrorKind::ConditionNotMatch.to_string(),
)
.set_source(e)
}
_ => new_std_io_error(e),
}
})?;

let w = FsWriter::new(target_path, tmp_path, f);

Expand Down Expand Up @@ -495,7 +507,19 @@ impl Access for FsBackend {

let f = f
.open(tmp_path.as_ref().unwrap_or(&target_path))
.map_err(new_std_io_error)?;
.map_err(|e| {
match e.kind() {
std::io::ErrorKind::AlreadyExists => {
// Map io AlreadyExists to opendal ConditionNotMatch
Error::new(
ErrorKind::ConditionNotMatch,
ErrorKind::ConditionNotMatch.to_string(),
)
.set_source(e)
}
_ => new_std_io_error(e),
}
})?;

Ok((RpWrite::new(), FsWriter::new(target_path, tmp_path, f)))
}
Expand Down

0 comments on commit beb0edb

Please sign in to comment.