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

mistaken use of kebab case could use a better error message #3200

Open
felix9 opened this issue Nov 10, 2024 · 3 comments
Open

mistaken use of kebab case could use a better error message #3200

felix9 opened this issue Nov 10, 2024 · 3 comments

Comments

@felix9
Copy link

felix9 commented Nov 10, 2024

If json keys are kebab case ("last-name"), it's natural to try something like

jq '.last-name'

which emits a confusing error message:

jq: error: name/0 is not defined at <top-level>, line 1:

this seems like a common enough problem that it might be worth making a special error message for expressions that look like that.

(alternatively, the jq language could support kebab-case literals. this might break some scripts, but it seems unlikely that anyone would deliberately write an expression that looks like kebab-case)

@itchyny
Copy link
Contributor

itchyny commented Nov 13, 2024

Looking for the function is done in the compilation phase, and it is difficult (or making the code messy) to tell that the function is the right hand side of a binary expression which has indexing in the left hand side and .... Also can we know the difference between .last - name and .last-name in the compilation phase?

@felix9
Copy link
Author

felix9 commented Nov 13, 2024

it looks to me like it wouldn't be too hard to add a heuristic check at the point of the error message. check if the source expression looks like unquoted skewer case, and suggest that might be the problem. I might have time/energy to write a POC patch this weekend

@wader
Copy link
Member

wader commented Nov 13, 2024

For context me and @felix9 talked a bit about this on mastodon https://fosstodon.org/@[email protected]/113455083464066624 specially that there is two cases, a compile time and runtime time case, and probably the compile time case is more common and might be an easier case for heuristics?

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

No branches or pull requests

3 participants