-
Notifications
You must be signed in to change notification settings - Fork 31
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
read_bytes_term() should raise EOFError instead of Exception #41
Comments
in some cases instead of custom exceptions, see kaitai-io/kaitai_struct_python_runtime#41
I agree that if the terminator is required and doesn't occur before EOF, the file appears to be truncated and therefore an With Another reason why I believe this is a slightly different error than a bare In PHP, I added an exception class Does anybody (@GreyCat, @armijnhemel, @dgelessus) have an opinion on this? |
Personally I am agnostic to this, but it might be good to keep things consistent across the different languages. Also, if there is more information available (which seems to be the case here), then there might be users that would like to know. A subclass of |
* Resolves #40 * Resolves #41 As explained in #40, this makes it easy to handle to all errors caused by invalid input data by using `kaitaistruct.KaitaiStructError` in a `try..except` statement. Three new exception types were added: `InvalidArgumentError`, `EndOfStreamError` and `NoTerminatorFoundError`. All changes to raised exceptions in this commit should be backward compatible, as we are only moving to subclasses of previously raised exceptions. `NoTerminatorFoundError` is a subclass of `EndOfStreamError` to address the suggestion in #41. Note that the `process_rotate_left` method could only raise `NotImplementedError` if someone called it manually (because KSC-generated parsers hardcode `group_size` to `1`, 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 derived `KaitaiStructError` (it's a programmer error, not a user input error). Most of our runtime libraries in other languages don't even have this `group_size` parameter, and if they do (C#, Java, Ruby), they also throw the equivalent of `NotImplementedError` (except the JavaScript runtime, which throws a plain string, which is _possible_ in JS but considered bad practice, so we should fix this).
read_bytes_term()
should raise EOFError instead of Exception to be consistent withread_bytes()
.Btw. it's funny that found this issue 1h later than the person that has reported #40
Even if #40 is implemented using a custom class, I'd suggest having both
read_bytes_term()
andread_bytes()
raise the same type of error.My use case is that I'm trying to detect when the packet that I'm parsing has been truncated so it would be helpful to be able to just do
except EOFError
(orexcept kaitaistruct.EOFError
) instead of having to parse the exception message.The text was updated successfully, but these errors were encountered: