-
Notifications
You must be signed in to change notification settings - Fork 201
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
Can Kaitai DSL describe an exception to be thrown on unexpected input? #650
Comments
The error you're hitting is likely the same as described in #568. It's Java-specific, most other languages won't encounter this problem. For the original ask, you'd probably be interested in stuff implemented in #435 — this would allow you to specify certain assertions/constraints that your data must adhere to. |
@GreyCat
Is my understanding correct? |
In 0.8, there is no validation functionality at all (and no "other rules" really), so all you can get from 0.8. 0.8 is not the absolute latest, it's latest stable release. 0.9+ unstable offers at least some of that functionality.
Can you clarify what exactly do you mean by "deep" way? The current idea of asserting/validating is exactly about throwing an exception, although with clear indication of which part of specification fails validation (i.e. not just some confusing NullPointerException in the middle of nowhere).
That is correct. I don't actually see much problems with Java code using |
Yup, I just picked the latest artifact from the Maven Central, and I'll probably check the 0.9 version later.
I wanted to say that I expected it to fail somewhere at a higher level because of a missing mapping or unexpected enum value explaining the reason why, not necessarily just because it gets a null from the generated hash map. Thanks! |
Hi,
I've recently came across Kaitai and I'm evaluating it so that I could get rid of manual parsing. My custom binary format is extremely simple:
Byte arrays above require simple type tags
0x00
for null values,0x01
for 1-byte-length arrays, and0x02
for 2-byte-length arrays. In short, this grammar can process such data:Now suppose the type tag is broken for whatever reason and indicates a type that is not registered in the
type_tag
enum above.Let's say, the actual type tag value is
0xDD
(and it doesn't map any type). Trying to parse such data the following exception is thrown:which points to:
The NPE encounters in the switch expression caused by
public static TypeTag byId(long id) { return byId.get(id); }
that returnsnull
for the unrecognized type tag0xDD
. If I'm not mistaken at understanding Scala code, currently the compiler does not provide any way of throwing an "unrecognized" exception inJavaCompiler.scala
. My question is: is there a way to tell the generated code to throw a custom exception on encountering illegal type tags? I would assume that I could add a new case for_
to theswitch-on
clauses above, but I didn't find anything in the documentation telling how to throw an exception to hide the obscureNullPointerException
.The text was updated successfully, but these errors were encountered: