From 015b49e298ea713ba26f9d1508b7e7e52694bd6f Mon Sep 17 00:00:00 2001 From: dqhl76 Date: Fri, 14 Jul 2023 15:41:38 +0800 Subject: [PATCH 1/2] fix: make seek invalid error more clear Signed-off-by: dqhl76 --- 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 7ce2247d3364..363719a3ffd0 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 51cf534725e7..ac01b33e7562 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 e26af95a7539..cb761523bda8 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 RangeReader { 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 c6a15231a2a4..1c3e02d5519c 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 88453c7708db..c48d31257bf0 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 for &'static str { ErrorKind::ConditionNotMatch => "ConditionNotMatch", ErrorKind::ContentTruncated => "ContentTruncated", ErrorKind::ContentIncomplete => "ContentIncomplete", + ErrorKind::InvalidInput => "InvalidInput", } } } From b1c30f12fcdd21fe31ebfeec9bcc21a30858f5a3 Mon Sep 17 00:00:00 2001 From: dqhl76 Date: Fri, 14 Jul 2023 15:59:21 +0800 Subject: [PATCH 2/2] fix: format file Signed-off-by: dqhl76 --- core/src/types/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/types/error.rs b/core/src/types/error.rs index c48d31257bf0..b530c16a179e 100644 --- a/core/src/types/error.rs +++ b/core/src/types/error.rs @@ -100,9 +100,9 @@ pub enum ErrorKind { /// - 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, + InvalidInput, } impl ErrorKind {