Skip to content

Conversation

itchyny
Copy link
Contributor

@itchyny itchyny commented Mar 10, 2025

This commit improves the parser and compiler error messages, making
it more easier to understand where in the filter the problem is.
Like modern compilers, jq will show the line in the filter where the
error occurred, will display squiggly line under the invalid token.

 $ ./jq -n '1 + 2 ( 3'    
jq: error: syntax error, unexpected '(', expecting end of file at <top-level>, line 1, column 7:
    1 + 2 ( 3
          ^
jq: 1 compile error

 $ ./jq -n '1 + $foo + 2'
jq: error: $foo is not defined at <top-level>, line 1, column 5:
    1 + $foo + 2
        ^^^^
jq: 1 compile error

This commit improves the parser and compiler error messages, making
it more easier to understand where in the filter the problem is.
Like modern compilers, jq will show the line in the filter where the
error occurred, will display squiggly line under the invalid token.
@itchyny itchyny force-pushed the improve-error-message-position branch from ba0089e to 467f441 Compare March 10, 2025 13:51
@itchyny itchyny added this to the 1.8 release milestone Mar 10, 2025
@itchyny itchyny force-pushed the improve-error-message-position branch 3 times, most recently from 180724a to 3c277a7 Compare March 11, 2025 12:21
@itchyny itchyny force-pushed the improve-error-message-position branch from 3c277a7 to 2f97147 Compare May 17, 2025 10:44
locfile_locate(locations, *loc, "jq: error: %s (Windows cmd shell quoting issues?)", s);
#else
locfile_locate(locations, *loc, "jq: error: %s (Unix shell quoting issues?)", s);
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Removed as it might be more confusing than useful to show for all parse errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's less likely an issue of quoting issue in my experience.

@itchyny itchyny force-pushed the improve-error-message-position branch from 2f97147 to cbfb060 Compare May 18, 2025 07:22
@itchyny itchyny merged commit b733dfa into jqlang:master May 18, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants