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

Output more metadata on expression errors, fix #1440 #1441

Merged
merged 3 commits into from
Jun 12, 2021
Merged

Conversation

sc1f
Copy link
Contributor

@sc1f sc1f commented Jun 9, 2021

This PR changes the validate_expressions API to output an expression error object versus just an error message.

For errors from ExprTk's parser (invalid symbol, mismatched parentheses, etc.), we use ExprTk's update_error method to generate a line and column number for the error. Because we pre-parse the expression strings, on certain expressions the line/column positions of a token that errored might not be totally accurate, as the parsed expression string (COLUMN1 + COLUMN2, vs. "Sales" + "Profit" as typed by the user) will not match 1:1 in terms of token position to the string the user typed. However, without doing a large amount of parsing and other validation, this is good enough for a generalized idea of where an error might be (especially as it does not output a range, just a line and a column number).

Each error object now contains the following keys:

  • error_message: a string that describes the error
  • line: an integer >= 0 that marks the line the error occurred on
  • column: an integer >= that marks the column position the error occurred on

Type errors and "Column does not exist" errors will always return 0 for both line and column.

Additionally, this test cleans up some missing definitions in index.d.ts as reported by #1440.

@sc1f sc1f force-pushed the expression-errors branch from 06ea336 to e0605c8 Compare June 9, 2021 13:41
@sc1f sc1f added C++ enhancement Feature requests or improvements labels Jun 9, 2021
@sc1f sc1f force-pushed the expression-errors branch from 85d1526 to 574c521 Compare June 10, 2021 04:13
Copy link
Member

@texodus texodus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks for the PR!

@texodus texodus merged commit 183da3f into master Jun 12, 2021
@texodus texodus deleted the expression-errors branch June 12, 2021 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ enhancement Feature requests or improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants