concerto
concerto copied to clipboard
Add file location information to ValidationExceptions and TypeNotFoundExceptions when possible
Is your feature request related to a problem? Please describe. Most errors include location information, but validation and type not found errors do not.
Describe the solution you'd like When validating a JSON instance against a model fails, provide location information for where the error occurred in the JSON instance.
When loading a model which has an unknown type, provide location information for where that type is used in the model.
Describe alternatives you've considered I haven't.
Additional context
Here is an example of an exception with location information (it inherits from BaseFileException
):
https://github.com/accordproject/concerto/blob/master/packages/concerto-core/lib/introspect/parseexception.js
Currently when running the CLI in those cases:
bash-3.2$ concerto generate --ctoFiles test/models/typenotfound.cto
Undeclared type BUBBLE in property org.accordproject.money.CryptoMonetaryAmount.doubleValue File 'test/models/typenotfound.cto': IllegalModelException: Undeclared type BUBBLE in property org.accordproject.money.CryptoMonetaryAmount.doubleValue File 'test/models/typenotfound.cto':
bash-3.2$
bash-3.2$ concerto validate --ctoFiles test/models/money.cto --sample test/data/sample2.json
Instance undefined invalid enum value true for field CurrencyCode ValidationException: Instance undefined invalid enum value true for field CurrencyCode
Compared to the case where a file location is available:
bash-3.2$ concerto generate --ctoFiles test/models/parseerror.cto
Expected "-->", "@", "default", "o", "optional", "}", comment, end of line, or whitespace but "e" found. File test/models/parseerror.cto line 14 column 1 ParseException: Expected "-->", "@", "default", "o", "optional", "}", comment, end of line, or whitespace but "e" found. File test/models/parseerror.cto line 14 column 1
Is this issue open?
@jeromesimeon
After some investigation, I found that in case of exceptions like IllegalModelException
the file location is passed as a parameter in the constructor (here). This location is read from the location
property of AST (here). If we can follow a similar approach for the exceptions mentioned in the issue, we can add file location there.
Can I start with this approach?