Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): core doesn't expose invalid input error anymore #4632

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bindings/java/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ impl Error {
ErrorKind::ConditionNotMatch => "ConditionNotMatch",
ErrorKind::ContentTruncated => "ContentTruncated",
ErrorKind::ContentIncomplete => "ContentIncomplete",
ErrorKind::InvalidInput => "InvalidInput",
_ => "Unexpected",
})?;
let message = env.new_string(format!("{:?}", self.inner))?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,5 @@ public enum Code {
ConditionNotMatch,
ContentTruncated,
ContentIncomplete,
InvalidInput,
}
}
4 changes: 0 additions & 4 deletions bindings/python/python/opendal/exceptions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,3 @@ class ContentIncomplete(Error):

pass

class InvalidInput(Error):
"""Invalid input"""

pass
2 changes: 0 additions & 2 deletions bindings/python/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ create_exception!(
);
create_exception!(opendal, ContentTruncatedError, Error, "Content truncated");
create_exception!(opendal, ContentIncompleteError, Error, "Content incomplete");
create_exception!(opendal, InvalidInputError, Error, "Invalid input");

pub fn format_pyerr(err: ocore::Error) -> PyErr {
use ocore::ErrorKind::*;
Expand All @@ -55,7 +54,6 @@ pub fn format_pyerr(err: ocore::Error) -> PyErr {
ConditionNotMatch => ConditionNotMatchError::new_err(err.to_string()),
ContentTruncated => ContentTruncatedError::new_err(err.to_string()),
ContentIncomplete => ContentIncompleteError::new_err(err.to_string()),
InvalidInput => InvalidInputError::new_err(err.to_string()),
_ => UnexpectedError::new_err(err.to_string()),
}
}
1 change: 0 additions & 1 deletion bindings/python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ fn _opendal(py: Python, m: &PyModule) -> PyResult<()> {
exception_module.add("ConditionNotMatch", py.get_type::<ConditionNotMatchError>())?;
exception_module.add("ContentTruncated", py.get_type::<ContentTruncatedError>())?;
exception_module.add("ContentIncomplete", py.get_type::<ContentIncompleteError>())?;
exception_module.add("InvalidInput", py.get_type::<InvalidInputError>())?;
m.add_submodule(exception_module)?;
py.import("sys")?
.getattr("modules")?
Expand Down
2 changes: 0 additions & 2 deletions core/src/raw/std_io_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub fn new_std_io_error(err: std::io::Error) -> Error {
NotFound => (ErrorKind::NotFound, false),
PermissionDenied => (ErrorKind::PermissionDenied, false),
AlreadyExists => (ErrorKind::AlreadyExists, false),
InvalidInput => (ErrorKind::InvalidInput, false),
Unsupported => (ErrorKind::Unsupported, false),

Interrupted | UnexpectedEof | TimedOut | WouldBlock => (ErrorKind::Unexpected, true),
Expand All @@ -59,7 +58,6 @@ pub(crate) fn format_std_io_error(err: Error) -> io::Error {
let kind = match err.kind() {
ErrorKind::NotFound => io::ErrorKind::NotFound,
ErrorKind::PermissionDenied => io::ErrorKind::PermissionDenied,
ErrorKind::InvalidInput => io::ErrorKind::InvalidInput,
_ => io::ErrorKind::Interrupted,
};

Expand Down
5 changes: 0 additions & 5 deletions core/src/services/alluxio/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
kind = match alluxio_err.status_code.as_str() {
"ALREADY_EXISTS" => ErrorKind::AlreadyExists,
"NOT_FOUND" => ErrorKind::NotFound,
"INVALID_ARGUMENT" => ErrorKind::InvalidInput,
_ => ErrorKind::Unexpected,
}
}
Expand Down Expand Up @@ -78,10 +77,6 @@ mod tests {
r#"{"statusCode":"NOT_FOUND","message":"The resource you requested does not exist"}"#,
ErrorKind::NotFound,
),
(
r#"{"statusCode":"INVALID_ARGUMENT","message":"The argument you provided is invalid"}"#,
ErrorKind::InvalidInput,
),
(
r#"{"statusCode":"INTERNAL_SERVER_ERROR","message":"Internal server error"}"#,
ErrorKind::Unexpected,
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/gridfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ impl Builder for GridFsBuilder {
Some(v) => v.clone(),
None => {
return Err(
Error::new(ErrorKind::InvalidInput, "connection_string is required")
Error::new(ErrorKind::ConfigInvalid, "connection_string is required")
.with_context("service", Scheme::Gridfs),
)
}
};
let database = match &self.database.clone() {
Some(v) => v.clone(),
None => {
return Err(Error::new(ErrorKind::InvalidInput, "database is required")
return Err(Error::new(ErrorKind::ConfigInvalid, "database is required")
.with_context("service", Scheme::Gridfs))
}
};
Expand Down
2 changes: 0 additions & 2 deletions core/src/services/hdfs_native/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ pub fn parse_hdfs_error(hdfs_error: HdfsError) -> Error {
false,
"checksums didn't match".to_string(),
),
HdfsError::InvalidPath(msg) => (ErrorKind::InvalidInput, false, msg.clone()),
HdfsError::InvalidArgument(msg) => (ErrorKind::InvalidInput, false, msg.clone()),
HdfsError::UrlParseError(err) => (ErrorKind::Unexpected, false, err.to_string()),
HdfsError::AlreadyExists(msg) => (ErrorKind::AlreadyExists, false, msg.clone()),
HdfsError::OperationFailed(msg) => (ErrorKind::Unexpected, false, msg.clone()),
Expand Down
6 changes: 3 additions & 3 deletions core/src/services/mongodb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,23 @@ impl Builder for MongodbBuilder {
Some(v) => v.clone(),
None => {
return Err(
Error::new(ErrorKind::InvalidInput, "connection_string is required")
Error::new(ErrorKind::ConfigInvalid, "connection_string is required")
.with_context("service", Scheme::Mongodb),
)
}
};
let database = match &self.config.database.clone() {
Some(v) => v.clone(),
None => {
return Err(Error::new(ErrorKind::InvalidInput, "database is required")
return Err(Error::new(ErrorKind::ConfigInvalid, "database is required")
.with_context("service", Scheme::Mongodb))
}
};
let collection = match &self.config.collection.clone() {
Some(v) => v.clone(),
None => {
return Err(
Error::new(ErrorKind::InvalidInput, "collection is required")
Error::new(ErrorKind::ConfigInvalid, "collection is required")
.with_context("service", Scheme::Mongodb),
)
}
Expand Down
1 change: 0 additions & 1 deletion core/src/services/seafile/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
let bs = body.copy_to_bytes(body.remaining());

let (kind, _retryable) = match parts.status.as_u16() {
400 => (ErrorKind::InvalidInput, false),
403 => (ErrorKind::PermissionDenied, false),
404 => (ErrorKind::NotFound, false),
520 => (ErrorKind::Unexpected, false),
Expand Down
1 change: 0 additions & 1 deletion core/src/services/yandex_disk/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ pub async fn parse_error(resp: Response<Buffer>) -> Result<Error> {
let bs = body.copy_to_bytes(body.remaining());

let (kind, retryable) = match parts.status.as_u16() {
400 => (ErrorKind::InvalidInput, false),
410 | 403 => (ErrorKind::PermissionDenied, false),
404 => (ErrorKind::NotFound, false),
// We should retry it when we get 423 error.
Expand Down
6 changes: 0 additions & 6 deletions core/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ 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 {
Expand Down Expand Up @@ -135,7 +131,6 @@ impl From<ErrorKind> for &'static str {
ErrorKind::ConditionNotMatch => "ConditionNotMatch",
ErrorKind::ContentTruncated => "ContentTruncated",
ErrorKind::ContentIncomplete => "ContentIncomplete",
ErrorKind::InvalidInput => "InvalidInput",
}
}
}
Expand Down Expand Up @@ -427,7 +422,6 @@ impl From<Error> for io::Error {
let kind = match err.kind() {
ErrorKind::NotFound => io::ErrorKind::NotFound,
ErrorKind::PermissionDenied => io::ErrorKind::PermissionDenied,
ErrorKind::InvalidInput => io::ErrorKind::InvalidInput,
_ => io::ErrorKind::Other,
};

Expand Down
Loading