-
Notifications
You must be signed in to change notification settings - Fork 9
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
Exception should Inhert from KegAppError or some base #135
Comments
Why do these need to inherit from some base? That is usually helpful for something like In the case of these exceptions, they are all distinct. I can't image ever using a construct like: try:
....
except KegBaseError as e:
# do something regardless of which Keg error it is |
I would pose the reverse question... why wouldn't you want all the exceptions in a library to inherit from a common base? The base exception is 2 lines and to my understanding adds no overhead (maybe a heap allocation?) and no complexity other than "hey, inherit from the base class" if we add a new exception type. I would move all the exceptions into their own module too Regardless my usecase is, flask has exception handlers that you can attach to the app and it would be helpful to catch all Also, as the Keg ecosystem expands, we can inject additional data into a Finally, it seems to be a reasonable practice across the community. This is how SQLAlchmey, Requests, Coverage does it... I'm sure there is more but that is the short list. |
I don't really care that much, I just don't think it adds any benefit to this type of library and it encourages the handling "all errors" as if they were the same thing/type when they are all very different. For example:
This smells to me. I just don't see a use case where treating all these exception the same is going to be the best architecture. If you aren't going to handle them explicitly (assuming that's what you mean by "manually") then IMO the exception should probably bubble to the surface instead of being caught in some
IMO YAGNI.
Yes, but those examples all have true exception hierarchies. Where catching one high-level exception would be a good practice and good architecture in many common cases. In Keg's case, with the exceptions we throw, there isn't really a hierarchy and I currently believe catching them all with some generic handler is likely an anti-pattern.
I deliberately did not do that for Keg because the exceptions were disparate and usage in the library was confined to their module. Unlike something like SQLAlchemy where you may have one exception used by a bunch of different code. Then it makes sense to move them all to a centralized exceptions module. I don't really care if you do the inheritance thing. I'm a -0 on it b/c it encourages a catch-all approach which doesn't currently make sense to me and feels like an anti-pattern. If you are a +1 then feel to move ahead. I'd be a -1 on moving the exceptions to a centralized module for Keg, although I do appreciate that pattern and have used it elsewhere when it seemed the better approach. Just doesn't feel to me like it applies here. If you are a +1 here, probably best to get Matt's opinion and let his vote be the tie breaker. Thanks for your thoughts. |
Base exception:
keg/keg/app.py
Lines 23 to 24 in dba2cf4
Config Exception:
keg/keg/config.py
Lines 18 to 19 in dba2cf4
View Exceptions:
keg/keg/web.py
Lines 42 to 43 in dba2cf4
Asset Exceptions:
keg/keg/assets.py
Lines 12 to 13 in dba2cf4
The text was updated successfully, but these errors were encountered: