Skip to content

Commit

Permalink
refactor(core): Return unexpected error while content incomplete happ…
Browse files Browse the repository at this point in the history
…en (apache#4633)

Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo authored and George-Miao committed Jun 5, 2024
1 parent 6ad1e68 commit 759373a
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 44 deletions.
2 changes: 0 additions & 2 deletions bin/ofs/src/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,6 @@ fn opendal_error2errno(err: opendal::Error) -> fuse3::Errno {
ErrorKind::PermissionDenied => Errno::from(libc::EACCES),
ErrorKind::AlreadyExists => Errno::from(libc::EEXIST),
ErrorKind::NotADirectory => Errno::from(libc::ENOTDIR),
ErrorKind::ContentTruncated => Errno::from(libc::EAGAIN),
ErrorKind::ContentIncomplete => Errno::from(libc::EIO),
_ => Errno::from(libc::ENOENT),
}
}
2 changes: 0 additions & 2 deletions bindings/java/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ impl Error {
ErrorKind::RateLimited => "RateLimited",
ErrorKind::IsSameFile => "IsSameFile",
ErrorKind::ConditionNotMatch => "ConditionNotMatch",
ErrorKind::ContentTruncated => "ContentTruncated",
ErrorKind::ContentIncomplete => "ContentIncomplete",
_ => "Unexpected",
})?;
let message = env.new_string(format!("{:?}", self.inner))?;
Expand Down
10 changes: 0 additions & 10 deletions bindings/python/python/opendal/exceptions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,3 @@ class ConditionNotMatch(Error):

pass

class ContentTruncated(Error):
"""Content truncated"""

pass

class ContentIncomplete(Error):
"""Content incomplete"""

pass

4 changes: 0 additions & 4 deletions bindings/python/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ create_exception!(
Error,
"Condition not match"
);
create_exception!(opendal, ContentTruncatedError, Error, "Content truncated");
create_exception!(opendal, ContentIncompleteError, Error, "Content incomplete");

pub fn format_pyerr(err: ocore::Error) -> PyErr {
use ocore::ErrorKind::*;
Expand All @@ -52,8 +50,6 @@ pub fn format_pyerr(err: ocore::Error) -> PyErr {
AlreadyExists => AlreadyExistsError::new_err(err.to_string()),
IsSameFile => IsSameFileError::new_err(err.to_string()),
ConditionNotMatch => ConditionNotMatchError::new_err(err.to_string()),
ContentTruncated => ContentTruncatedError::new_err(err.to_string()),
ContentIncomplete => ContentIncompleteError::new_err(err.to_string()),
_ => UnexpectedError::new_err(err.to_string()),
}
}
2 changes: 0 additions & 2 deletions bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ fn _opendal(py: Python, m: &PyModule) -> PyResult<()> {
exception_module.add("AlreadyExists", py.get_type::<AlreadyExistsError>())?;
exception_module.add("IsSameFile", py.get_type::<IsSameFileError>())?;
exception_module.add("ConditionNotMatch", py.get_type::<ConditionNotMatchError>())?;
exception_module.add("ContentTruncated", py.get_type::<ContentTruncatedError>())?;
exception_module.add("ContentIncomplete", py.get_type::<ContentIncompleteError>())?;
m.add_submodule(exception_module)?;
py.import("sys")?
.getattr("modules")?
Expand Down
8 changes: 4 additions & 4 deletions core/src/raw/http_util/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ fn check(expect: u64, actual: u64) -> Result<()> {
match actual.cmp(&expect) {
Ordering::Equal => Ok(()),
Ordering::Less => Err(Error::new(
ErrorKind::ContentIncomplete,
&format!("reader got too little data, expect: {expect}, actual: {actual}"),
ErrorKind::Unexpected,
&format!("http response got too little data, expect: {expect}, actual: {actual}"),
)
.set_temporary()),
Ordering::Greater => Err(Error::new(
ErrorKind::ContentTruncated,
&format!("reader got too much data, expect: {expect}, actual: {actual}"),
ErrorKind::Unexpected,
&format!("http response got too much data, expect: {expect}, actual: {actual}"),
)
.set_temporary()),
}
Expand Down
20 changes: 0 additions & 20 deletions core/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,6 @@ pub enum ErrorKind {
/// As OpenDAL cannot handle the `condition not match` error, it will always return this error to users.
/// So users could to handle this error by themselves.
ConditionNotMatch,
/// The content is truncated.
///
/// This error kind means there are more content to come but been truncated.
///
/// For examples:
///
/// - Users expected to read 1024 bytes, but service returned more bytes.
/// - Service expected to write 1024 bytes, but users write more bytes.
ContentTruncated,
/// The content is incomplete.
///
/// This error kind means expect content length is not reached.
///
/// For examples:
///
/// - Users expected to read 1024 bytes, but service returned less bytes.
/// - Service expected to write 1024 bytes, but users write less bytes.
ContentIncomplete,
}

impl ErrorKind {
Expand Down Expand Up @@ -129,8 +111,6 @@ impl From<ErrorKind> for &'static str {
ErrorKind::RateLimited => "RateLimited",
ErrorKind::IsSameFile => "IsSameFile",
ErrorKind::ConditionNotMatch => "ConditionNotMatch",
ErrorKind::ContentTruncated => "ContentTruncated",
ErrorKind::ContentIncomplete => "ContentIncomplete",
}
}
}
Expand Down

0 comments on commit 759373a

Please sign in to comment.