caze
caze copied to clipboard
Exception Interceptor makes exception un-rescuable
The exception interceptor feature is intended to make clear which use case raised a given error, including the use case name in the exception. This is a good idea for general tracing of the error.
The issue here is that since the class is created dynamically, it is not referenceable by the caller and therefore not rescuable precisely. Further, since the new exception doesn't even inherit from the previous one, it is only rescuable if the rescue clause targets the StandardError
class.
One obvious solution would be to at least inherit from the previous class, but this won't work because case
has no way of figuring out how to construct the error it gets (since the error isn't required to follow any protocol).
Finally, I think the feature in itself doesn't add that much and it causes these problems, so it might be better removed.
- Example:
class A
include Case
class E < StandardError
has_use_case :b, A::B # b throws the A::E error
end
begin
A.b
rescue A::B::E => e
# won't happen because this isn't even defined on this point
rescue A::E => e
# won't happen, because the re-thrown error doesn't inherit from this one
# it inherits from StandardError
rescue => e
# will happen and that's the only way to catch the error
end