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

Improve Error & Warning Handling #621

Open
Lukas113 opened this issue Oct 8, 2024 · 0 comments
Open

Improve Error & Warning Handling #621

Lukas113 opened this issue Oct 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Lukas113
Copy link
Collaborator

Lukas113 commented Oct 8, 2024

We could/should improve the Karabo error and warning handling. What I mean by that is the following:

Error-Handling

  • For errors we throw, we should always use custom errors. The reason is because if someone wants to do proper error-handling on their side, we would make it much easier for them. They could just e.g. catch KaraboError (or any inherited error from KaraboError) to just handle errors we throw. However, we also should also follow the Python built-in exception specification. Therefore I suggest the following error-structure, which inherit always from KaraboError and the according built-in exception:
class KaraboError(Exception): ...

class KaraboRuntimeError(KaraboError, RuntimeError): ...

class KaraboValueError(KaraboError, ValueError): ...

class MaybeAnEvenMoreSpecificError(KaraboRuntimeError): ...

# other exceptions

Waring-Handling

  • For warnings, we should also use custom warnings. This makes it way easier for a third-party user to ignore karabo-specific warnings without ignoring other warnings of the same kind. The inheritance structure is the same as for exceptions:
class KaraboWarning(Warning): ...

class KaraboUserWarning(KaraboWarning, UserWarning): ...

class KaraboFutureWarning(KaraboWarning, FutureWarning): ...

class MaybeAnEvenMoreSpecificWarning(KaraboUserWarning): ...

This specific approach would enhance the error and warning handling possibilities for a third-party user by a lot. The only requirement for us to just throw KaraboError (inherited) and use KaraboWarning (inherited).

@Lukas113 Lukas113 added the enhancement New feature or request label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant