ASN1.js
ASN1.js copied to clipboard
Improved error handling
It would be good to see improved error handling so that programatic handling and debugging of encoding problems can be handled better.
For instance, the error returned at org/pkijs/asn.js:4795 gives no indication of errors buried deep in the schema but instead returns simply (and quite possibly incorrectly) 'Wrong values for choice type'.
Yes, the error hadnling is still not good in ASN1js. But the error you mentioned is a real error (and it is correct error, 100%). The error you got when in schema and in data you have different values in CHOICE type. For instance when in schema you have ASN1_CONSTRUCTED but in data you have ASN1_PRIMITIVE.
If the schema fails to verify below a CHOICE type then the error only mentions the invalid choice type when in fact the error could be buried deeper. This is due to the recursive compareSchema function called on each of the choices.
Sure, and you can verify "error" field of nested types in order to find out an "initial object with error". If you have any proposals/recommendations about error handling feel free to say me about them.
As i have seen this ticket i wanted to bump in the solution we made on our fork of the library.
https://github.com/ESTOS/ASN1.js
The different validation issues are now enum value based (no longer text based) The validation carries a context while it parses and thus exposes where in a hierarchical structure an error has occured (NAME:SUBNAME:SUBSUBNAME, if no name is provided the tagclass-tagname is used instead) The errors are now an array and thus may contain mulitple errors
The behaviour of the validation is configurable with VerifyOptions (continueOnError allowLargerThanSchema)
Existing test succeeded, added a bunch of new test for optionals, choices and schema validation in general.
(Have no expectation that this is getting merged as the changes are quite large but maybe someone hops in and needs a solution and may be a good start to additional improve diagnsotics)