This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 74db2547b refactor(core): Add ErrorKind InvalidInput to indicate users
input error (#2637)
74db2547b is described below
commit 74db2547b10dc93cb957809f1b696f796b552c3e
Author: dqhl76 <[email protected]>
AuthorDate: Fri Jul 14 16:08:19 2023 +0800
refactor(core): Add ErrorKind InvalidInput to indicate users input error
(#2637)
* fix: make seek invalid error more clear
Signed-off-by: dqhl76 <[email protected]>
* fix: format file
Signed-off-by: dqhl76 <[email protected]>
---------
Signed-off-by: dqhl76 <[email protected]>
---
core/src/raw/oio/cursor.rs | 4 ++--
core/src/raw/oio/into_blocking_reader/from_fd.rs | 4 ++--
core/src/raw/oio/into_reader/by_range.rs | 2 +-
core/src/raw/oio/into_reader/from_fd.rs | 4 ++--
core/src/types/error.rs | 5 +++++
5 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/core/src/raw/oio/cursor.rs b/core/src/raw/oio/cursor.rs
index 7ce2247d3..363719a3f 100644
--- a/core/src/raw/oio/cursor.rs
+++ b/core/src/raw/oio/cursor.rs
@@ -84,7 +84,7 @@ impl oio::Read for Cursor {
Some(n) if n >= 0 => n as u64,
_ => {
return Poll::Ready(Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::InvalidInput,
"invalid seek to a negative or overflowing position",
)))
}
@@ -127,7 +127,7 @@ impl oio::BlockingRead for Cursor {
Some(n) if n >= 0 => n as u64,
_ => {
return Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::InvalidInput,
"invalid seek to a negative or overflowing position",
))
}
diff --git a/core/src/raw/oio/into_blocking_reader/from_fd.rs
b/core/src/raw/oio/into_blocking_reader/from_fd.rs
index 51cf53472..ac01b33e7 100644
--- a/core/src/raw/oio/into_blocking_reader/from_fd.rs
+++ b/core/src/raw/oio/into_blocking_reader/from_fd.rs
@@ -90,7 +90,7 @@ where
match base.checked_add(offset) {
Some(n) if n < 0 => Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::InvalidInput,
"invalid seek to a negative or overflowing position",
)),
Some(n) => {
@@ -104,7 +104,7 @@ where
Ok(self.offset - self.start)
}
None => Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::InvalidInput,
"invalid seek to a negative or overflowing position",
)),
}
diff --git a/core/src/raw/oio/into_reader/by_range.rs
b/core/src/raw/oio/into_reader/by_range.rs
index e26af95a7..cb761523b 100644
--- a/core/src/raw/oio/into_reader/by_range.rs
+++ b/core/src/raw/oio/into_reader/by_range.rs
@@ -114,7 +114,7 @@ impl<A: Accessor> RangeReader<A> {
Some(n) if n >= 0 => n as u64,
_ => {
return Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::InvalidInput,
"invalid seek to a negative or overflowing position",
))
}
diff --git a/core/src/raw/oio/into_reader/from_fd.rs
b/core/src/raw/oio/into_reader/from_fd.rs
index c6a15231a..1c3e02d55 100644
--- a/core/src/raw/oio/into_reader/from_fd.rs
+++ b/core/src/raw/oio/into_reader/from_fd.rs
@@ -93,7 +93,7 @@ where
match base.checked_add(offset) {
Some(n) if n < 0 => Poll::Ready(Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::InvalidInput,
"invalid seek to a negative or overflowing position",
))),
Some(n) => {
@@ -109,7 +109,7 @@ where
Poll::Ready(Ok(self.offset - self.start))
}
None => Poll::Ready(Err(Error::new(
- ErrorKind::Unexpected,
+ ErrorKind::InvalidInput,
"invalid seek to a negative or overflowing position",
))),
}
diff --git a/core/src/types/error.rs b/core/src/types/error.rs
index 88453c770..b530c16a1 100644
--- a/core/src/types/error.rs
+++ b/core/src/types/error.rs
@@ -99,6 +99,10 @@ pub enum ErrorKind {
/// - Users expected to read 1024 bytes, but service returned less bytes.
/// - Service expected to write 1024 bytes, but users write less bytes.
ContentIncomplete,
+ /// The input is invalid.
+ ///
+ /// For example, user try to seek to a negative position
+ InvalidInput,
}
impl ErrorKind {
@@ -130,6 +134,7 @@ impl From<ErrorKind> for &'static str {
ErrorKind::ConditionNotMatch => "ConditionNotMatch",
ErrorKind::ContentTruncated => "ContentTruncated",
ErrorKind::ContentIncomplete => "ContentIncomplete",
+ ErrorKind::InvalidInput => "InvalidInput",
}
}
}