This is an automated email from the ASF dual-hosted git repository.

manjusaka pushed a commit to branch manjusaka/polish-exception
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/manjusaka/polish-exception by 
this push:
     new 720122b0c Update code
720122b0c is described below

commit 720122b0c9d07e86e26a64a21ae5a04895761168
Author: Manjusaka <[email protected]>
AuthorDate: Tue Nov 7 12:40:31 2023 +0800

    Update code
    
    Signed-off-by: Manjusaka <[email protected]>
---
 bindings/python/python/opendal/exceptions.pyi | 31 +++++++++-------
 bindings/python/src/errors.rs                 | 52 ++++++++-------------------
 bindings/python/src/lib.rs                    |  1 +
 3 files changed, 33 insertions(+), 51 deletions(-)

diff --git a/bindings/python/python/opendal/exceptions.pyi 
b/bindings/python/python/opendal/exceptions.pyi
index 60c0ddaff..a14f25c26 100644
--- a/bindings/python/python/opendal/exceptions.pyi
+++ b/bindings/python/python/opendal/exceptions.pyi
@@ -15,67 +15,72 @@
 # specific language governing permissions and limitations
 # under the License.
 
-class Unexpected(Exception):
+class Error(Exception):
+    """Base class for exceptions in this module."""
+
+    pass
+
+class Unexpected(Error):
     """Unexpected errors"""
 
     pass
 
-class Unsupported(Exception):
+class Unsupported(Error):
     """Unsupported operation"""
 
     pass
 
-class ConfigInvalid(Exception):
+class ConfigInvalid(Error):
     """Config is invalid"""
 
     pass
 
-class NotFound(Exception):
+class NotFound(Error):
     """Not found"""
 
     pass
 
-class PermissionDenied(Exception):
+class PermissionDenied(Error):
     """Permission denied"""
 
     pass
 
-class IsADirectory(Exception):
+class IsADirectory(Error):
     """Is a directory"""
 
     pass
 
-class NotADirectory(Exception):
+class NotADirectory(Error):
     """Not a directory"""
 
     pass
 
-class AlreadyExists(Exception):
+class AlreadyExists(Error):
     """Already exists"""
 
     pass
 
-class IsSameFile(Exception):
+class IsSameFile(Error):
     """Is same file"""
 
     pass
 
-class ConditionNotMatch(Exception):
+class ConditionNotMatch(Error):
     """Condition not match"""
 
     pass
 
-class ContentTruncated(Exception):
+class ContentTruncated(Error):
     """Content truncated"""
 
     pass
 
-class ContentIncomplete(Exception):
+class ContentIncomplete(Error):
     """Content incomplete"""
 
     pass
 
-class InvalidInput(Exception):
+class InvalidInput(Error):
     """Invalid input"""
 
     pass
diff --git a/bindings/python/src/errors.rs b/bindings/python/src/errors.rs
index 93a8acf4e..45bff4060 100644
--- a/bindings/python/src/errors.rs
+++ b/bindings/python/src/errors.rs
@@ -20,49 +20,25 @@ use pyo3::exceptions::PyException;
 
 use crate::*;
 
-create_exception!(opendal, UnexpectedError, PyException, "Unexpected errors");
-create_exception!(
-    opendal,
-    UnsupportedError,
-    PyException,
-    "Unsupported operation"
-);
-create_exception!(
-    opendal,
-    ConfigInvalidError,
-    PyException,
-    "Config is invalid"
-);
-create_exception!(opendal, NotFoundError, PyException, "Not found");
-create_exception!(
-    opendal,
-    PermissionDeniedError,
-    PyException,
-    "Permission denied"
-);
-create_exception!(opendal, IsADirectoryError, PyException, "Is a directory");
-create_exception!(opendal, NotADirectoryError, PyException, "Not a directory");
-create_exception!(opendal, AlreadyExistsError, PyException, "Already exists");
-create_exception!(opendal, IsSameFileError, PyException, "Is same file");
+create_exception!(opendal, Error, PyException, "OpenDAL Base Exception");
+create_exception!(opendal, UnexpectedError, Error, "Unexpected errors");
+create_exception!(opendal, UnsupportedError, Error, "Unsupported operation");
+create_exception!(opendal, ConfigInvalidError, Error, "Config is invalid");
+create_exception!(opendal, NotFoundError, Error, "Not found");
+create_exception!(opendal, PermissionDeniedError, Error, "Permission denied");
+create_exception!(opendal, IsADirectoryError, Error, "Is a directory");
+create_exception!(opendal, NotADirectoryError, Error, "Not a directory");
+create_exception!(opendal, AlreadyExistsError, Error, "Already exists");
+create_exception!(opendal, IsSameFileError, Error, "Is same file");
 create_exception!(
     opendal,
     ConditionNotMatchError,
-    PyException,
+    Error,
     "Condition not match"
 );
-create_exception!(
-    opendal,
-    ContentTruncatedError,
-    PyException,
-    "Content truncated"
-);
-create_exception!(
-    opendal,
-    ContentIncompleteError,
-    PyException,
-    "Content incomplete"
-);
-create_exception!(opendal, InvalidInputError, PyException, "Invalid input");
+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::*;
diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs
index 8952e8766..076c75696 100644
--- a/bindings/python/src/lib.rs
+++ b/bindings/python/src/lib.rs
@@ -95,6 +95,7 @@ fn _opendal(py: Python, m: &PyModule) -> PyResult<()> {
         .set_item("opendal.layers", layers_module)?;
 
     let exception_module = PyModule::new(py, "exceptions")?;
+    exception_module.add("Error", py.get_type::<Error>())?;
     exception_module.add("Unexpected", py.get_type::<UnexpectedError>())?;
     exception_module.add("Unsupported", py.get_type::<UnsupportedError>())?;
     exception_module.add("ConfigInvalid", 
py.get_type::<ConfigInvalidError>())?;

Reply via email to