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

Enhancement: Include the file name in parse error messaging #1553

Open
GreenGremlin opened this issue Dec 12, 2017 · 7 comments · May be fixed by #3146
Open

Enhancement: Include the file name in parse error messaging #1553

GreenGremlin opened this issue Dec 12, 2017 · 7 comments · May be fixed by #3146

Comments

@GreenGremlin
Copy link

It would be helpful if the filename were included in parse error messages. While this could fairly easily be handled by a script, it would be nice if this functionality was included in jq.

Example script

#!/usr/bin/env bash

set -e

for file in data/*.json; do
    some_data=$(jq . file)
done

Currently, a parse error produces the following output.

$ ./parse_data.sh
parse error: Expected another key-value pair at line 20, column 3

It would be helpful if it output something like this.

$ ./parse_data.sh
Error parsing file data/2017-10-data.json: Expected another key-value pair at line 20, column 3

Even better, this feature could be added behind a --verbose flag and include the context of the error.

$ ./parse_data.sh
Error parsing file data/2017-10-data.json:

  19 |    "name": "Bob Smith",
> 20 |   },
        ^
  21 |   {

Expected another key-value pair at line 20, column 3
@nicowilliams
Copy link
Contributor

I believe this is already so in master. 1.6 is coming.

@chbrown
Copy link

chbrown commented Mar 5, 2019

+1 for this enhancement 😄

Even on jq-1.6 (as reported by jq --version), parse errors still return the same filename-agnostic message.

@bf
Copy link

bf commented May 7, 2023

Still an issue in 2023. There should be a switch that includes the full file path in the erorr message.

This is especially a pain in the rear when processing thousands of small json files with jq in parallel fashion.

@reythia
Copy link

reythia commented Jun 30, 2024

7 years later... still not implemented 🤦‍♂️

@emanuele6
Copy link
Member

🤦‍♂️

wader added a commit to wader/jq that referenced this issue Jun 30, 2024
wader added a commit to wader/jq that referenced this issue Jun 30, 2024
@wader wader linked a pull request Jun 30, 2024 that will close this issue
@wader
Copy link
Member

wader commented Jun 30, 2024

Did a draft PR #3146

I wonder what @nicowilliams referred to about as this being fixed in master? maybe reporting of current name:line of input on uncaught error? that is the only place currently where i see jq_util_input_get_position is used

@alxndrsn
Copy link

alxndrsn commented Jul 4, 2024

I wonder what @nicowilliams referred to about as this being fixed in master?

Here's an example output of calling jq 1.6 over thousands of JSON files:

...
parse error: Invalid numeric literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 16
parse error: Invalid numeric literal at line 1, column 16
parse error: Invalid numeric literal at line 1, column 16
parse error: Invalid numeric literal at line 1, column 16
parse error: Invalid literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 16
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 5
jq: error (at ./573455af-5842-48b7-9add-7a7c0349b502.json:260): Cannot index array with string "foo"
parse error: Invalid numeric literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid literal at line 1, column 5
parse error: Invalid literal at line 1, column 5
parse error: Invalid literal at line 1, column 5
parse error: Invalid literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 15
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 4
parse error: Invalid numeric literal at line 2, column 0
parse error: Invalid numeric literal at line 1, column 3
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 15
parse error: Invalid numeric literal at line 2, column 0
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 3
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 3
...

...so there is definitely some type of error which shows the filename!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants