Custom errors should inherit from `StandardError` (not `Exception`)
generalmimon opened this issue · comments
It means you should always inherit from
StandardError
, and NEVER fromException
. Inheriting from Exception is bad because it breaks the expected behavior of rescue. People will think they're rescuing all application-level errors but yours will just sail on through.
kaitai_struct_ruby_runtime/lib/kaitai/struct/struct.rb
Lines 688 to 692 in ecf6751
But UnexpectedDataError
should be left as is, because it only remains for compatibility with 0.8 and older KS versions (and will be eventually removed):
kaitai_struct_ruby_runtime/lib/kaitai/struct/struct.rb
Lines 78 to 84 in ecf6751
Yeah, this issue is also reported by RuboCop:
lib/kaitai/struct/struct.rb:692:27: W: [Correctable] Lint/InheritException: Inherit from StandardError instead of Exception.
class KaitaiStructError < Exception
^^^^^^^^^
We should adopt kaitai-io/kaitai_struct_visualizer#38 for runtime library too, and make sure that RuboCop at least doesn't issue any warnings.