Skip to content

Commit 74db254

Browse files
authored
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]>
1 parent bdd79f0 commit 74db254

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

core/src/raw/oio/cursor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl oio::Read for Cursor {
8484
Some(n) if n >= 0 => n as u64,
8585
_ => {
8686
return Poll::Ready(Err(Error::new(
87-
ErrorKind::Unexpected,
87+
ErrorKind::InvalidInput,
8888
"invalid seek to a negative or overflowing position",
8989
)))
9090
}
@@ -127,7 +127,7 @@ impl oio::BlockingRead for Cursor {
127127
Some(n) if n >= 0 => n as u64,
128128
_ => {
129129
return Err(Error::new(
130-
ErrorKind::Unexpected,
130+
ErrorKind::InvalidInput,
131131
"invalid seek to a negative or overflowing position",
132132
))
133133
}

core/src/raw/oio/into_blocking_reader/from_fd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ where
9090

9191
match base.checked_add(offset) {
9292
Some(n) if n < 0 => Err(Error::new(
93-
ErrorKind::Unexpected,
93+
ErrorKind::InvalidInput,
9494
"invalid seek to a negative or overflowing position",
9595
)),
9696
Some(n) => {
@@ -104,7 +104,7 @@ where
104104
Ok(self.offset - self.start)
105105
}
106106
None => Err(Error::new(
107-
ErrorKind::Unexpected,
107+
ErrorKind::InvalidInput,
108108
"invalid seek to a negative or overflowing position",
109109
)),
110110
}

core/src/raw/oio/into_reader/by_range.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<A: Accessor> RangeReader<A> {
114114
Some(n) if n >= 0 => n as u64,
115115
_ => {
116116
return Err(Error::new(
117-
ErrorKind::Unexpected,
117+
ErrorKind::InvalidInput,
118118
"invalid seek to a negative or overflowing position",
119119
))
120120
}

core/src/raw/oio/into_reader/from_fd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ where
9393

9494
match base.checked_add(offset) {
9595
Some(n) if n < 0 => Poll::Ready(Err(Error::new(
96-
ErrorKind::Unexpected,
96+
ErrorKind::InvalidInput,
9797
"invalid seek to a negative or overflowing position",
9898
))),
9999
Some(n) => {
@@ -109,7 +109,7 @@ where
109109
Poll::Ready(Ok(self.offset - self.start))
110110
}
111111
None => Poll::Ready(Err(Error::new(
112-
ErrorKind::Unexpected,
112+
ErrorKind::InvalidInput,
113113
"invalid seek to a negative or overflowing position",
114114
))),
115115
}

core/src/types/error.rs

+5
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ pub enum ErrorKind {
9999
/// - Users expected to read 1024 bytes, but service returned less bytes.
100100
/// - Service expected to write 1024 bytes, but users write less bytes.
101101
ContentIncomplete,
102+
/// The input is invalid.
103+
///
104+
/// For example, user try to seek to a negative position
105+
InvalidInput,
102106
}
103107

104108
impl ErrorKind {
@@ -130,6 +134,7 @@ impl From<ErrorKind> for &'static str {
130134
ErrorKind::ConditionNotMatch => "ConditionNotMatch",
131135
ErrorKind::ContentTruncated => "ContentTruncated",
132136
ErrorKind::ContentIncomplete => "ContentIncomplete",
137+
ErrorKind::InvalidInput => "InvalidInput",
133138
}
134139
}
135140
}

0 commit comments

Comments
 (0)