Skip to content
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

Add file location information to ValidationExceptions and TypeNotFoundExceptions when possible #99

Open
jeromesimeon opened this issue Oct 4, 2019 · 3 comments
Labels
Difficulty: Medium Stale Type: Enhancement ✨ Improvement to process or efficiency

Comments

@jeromesimeon
Copy link
Member

jeromesimeon commented Oct 4, 2019

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
@rusty-tendrils
Copy link

Is this issue open?

@kailash360
Copy link

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

Copy link
Contributor

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Medium Stale Type: Enhancement ✨ Improvement to process or efficiency
Projects
None yet
Development

No branches or pull requests

4 participants