concerto icon indicating copy to clipboard operation
concerto copied to clipboard

Add file location information to ValidationExceptions and TypeNotFoundExceptions when possible

Open jeromesimeon opened this issue 5 years ago • 2 comments

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

jeromesimeon avatar Oct 04 '19 16:10 jeromesimeon

Is this issue open?

rusty-tendrils avatar Feb 06 '21 15:02 rusty-tendrils

@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?

kailash360 avatar Mar 06 '24 14:03 kailash360