Skip to content

refactor(binding/python): Add multiple custom exception for each of error code in Rust Core#3492

Merged
Xuanwo merged 7 commits intomainfrom
manjusaka/polish-exception
Nov 7, 2023
Merged

refactor(binding/python): Add multiple custom exception for each of error code in Rust Core#3492
Xuanwo merged 7 commits intomainfrom
manjusaka/polish-exception

Conversation

@Zheaoli
Copy link
Copy Markdown
Member

@Zheaoli Zheaoli commented Nov 6, 2023

Signed-off-by: Manjusaka me@manjusaka.me

@Zheaoli Zheaoli requested a review from messense as a code owner November 6, 2023 13:01
…rror code in Rust Core

Signed-off-by: Manjusaka <me@manjusaka.me>
@Zheaoli Zheaoli force-pushed the manjusaka/polish-exception branch from 5242d1c to d95d518 Compare November 6, 2023 13:01
@Zheaoli Zheaoli changed the title reactor(binding/python): Add multiple custom exception for each of error code in Rust Core refactor(binding/python): Add multiple custom exception for each of error code in Rust Core Nov 6, 2023
@github-actions github-actions Bot added the releases-note/refactor The PR does a refactor on code or has a title that begins with "refactor" label Nov 6, 2023
Comment thread bindings/python/src/errors.rs Outdated
Comment thread bindings/python/python/opendal/exceptions.pyi Outdated
Comment thread bindings/python/src/errors.rs
@Zheaoli Zheaoli marked this pull request as draft November 6, 2023 13:10
Signed-off-by: Manjusaka <me@manjusaka.me>
Comment thread bindings/python/upgrade.md Outdated
Signed-off-by: Manjusaka <me@manjusaka.me>
@Zheaoli Zheaoli marked this pull request as ready for review November 6, 2023 16:36
Copy link
Copy Markdown
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM, @messense would you like to take another review?

Copy link
Copy Markdown
Member

@messense messense left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should still be a catch-all opendal Exception just like the original Error type, other exceptions should subclass from it, forming an exception hierarchy.

See also PyO3/pyo3#3452

@Xuanwo
Copy link
Copy Markdown
Member

Xuanwo commented Nov 7, 2023

I think there should still be a catch-all opendal Exception just like the original Error type, other exceptions should subclass from it, forming an exception hierarchy.

So we will have opendal.exceptions.Error and all other exceptions are subclasses of it?

@messense
Copy link
Copy Markdown
Member

messense commented Nov 7, 2023

So we will have opendal.exceptions.Error and all other exceptions are subclasses of it?

Exactly, to catch any opendal exception, user should not need to catch Exception because that would also catch non-opendal exceptions.

A good exception hierarchy example is https://github.com/psf/requests/blob/main/src/requests/exceptions.py

@Zheaoli
Copy link
Copy Markdown
Member Author

Zheaoli commented Nov 7, 2023

So we will have opendal.exceptions.Error and all other exceptions are subclasses of it?

Exactly, to catch any opendal exception, user should not need to catch Exception because that would also catch non-opendal exceptions.

A good exception hierarchy example is https://github.com/psf/requests/blob/main/src/requests/exceptions.py

SGTM

Signed-off-by: Manjusaka <me@manjusaka.me>
@Zheaoli Zheaoli requested a review from messense November 7, 2023 04:43
Copy link
Copy Markdown
Member

@messense messense left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also add a test case to ensure that catching any opendal exception using Error works?

Comment thread bindings/python/upgrade.md Outdated
Signed-off-by: Manjusaka <me@manjusaka.me>
Comment thread bindings/python/tests/test_sync_copy.py Outdated
This reverts commit 1d7d5a7.
Signed-off-by: Manjusaka <me@manjusaka.me>
@Xuanwo Xuanwo merged commit 87a7ac1 into main Nov 7, 2023
@Xuanwo Xuanwo deleted the manjusaka/polish-exception branch November 7, 2023 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

releases-note/refactor The PR does a refactor on code or has a title that begins with "refactor"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants