Skip to content

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

Merged
texodus merged 3 commits intomasterfrom
expression-errors
Jun 12, 2021
Merged

Output more metadata on expression errors, fix #1440#1441
texodus merged 3 commits intomasterfrom
expression-errors

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

Development

Successfully merging this pull request may close these issues.

2 participants