Adopt a system of exceptions derived from KaitaiStructError #80
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As explained in #40, this makes it easy to handle to all errors caused by invalid input data by using
kaitaistruct.KaitaiStructErrorin atry..exceptstatement. Three new exception types were added:InvalidArgumentError,EndOfStreamErrorandNoTerminatorFoundError. All changes to raised exceptions in this commit should be backward compatible, as we are only moving to subclasses of previously raised exceptions.NoTerminatorFoundErroris a subclass ofEndOfStreamErrorto address the suggestion in #41.Note that the
process_rotate_leftmethod could only raiseNotImplementedErrorif someone called it manually (because KSC-generated parsers hardcodegroup_sizeto1, see https://github.com/kaitai-io/kaitai_struct_compiler/blob/c23ec2ca88d84042edba76f70c1f003d062b7585/shared/src/main/scala/io/kaitai/struct/languages/PythonCompiler.scala#L211), so it makes no sense to raise an exception derivedKaitaiStructError(it's a programmer error, not a user input error). Most of our runtime libraries in other languages don't even have thisgroup_sizeparameter, and if they do (C#, Java, Ruby), they also throw the equivalent ofNotImplementedError(except the JavaScript runtime, which throws a plain string, which is possible in JS but considered bad practice, so we should fix this).