Skip to content

Make ? give no output on a type mismatch and stop hiding undefined functions - #83

Merged
davesnx merged 2 commits into
mainfrom
fix/optional-type-error-empty
Nov 9, 2026
Merged

davesnx merged 2 commits into
mainfrom
fix/optional-type-error-empty

Conversation

@davesnx

@davesnx davesnx commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Refs #62.

? turned every runtime error into null, so a path through irregular data printed null values for elements of the wrong type. It now gives null only for an absent value.

# users: alice has no metadata; bob's preferences are ["dark_mode", {"notifications": {"email": ...}}]
query-json '.users[].metadata?.preferences?[]?.notifications?.email?'
# "bob@example.com"
  • ? and try without catch give no output on a type mismatch, as jq does: "x" | .a?, 1 | .[]?, null | .[]?, 123 | keys?.
  • An absent value still gives null: a missing key, a key or an index on null, an index out of bounds, first? on [].
  • ? and try without catch no longer hide an undefined function: foo? reports the error. try foo catch .kind still gives "undefined_function".
  • A slice on null or a number is an error; it used to stop with an OCaml Assertion failed.

Runtime_error.when_caught is the one place that maps an error kind to null, no output, or propagation. Its match lists every kind.

Query on the issue's data main (2c08a49) This branch (822534e) jq 1.7
.users[].metadata?.preferences?[]?.notifications?.email? null, null, "bob@example.com" "bob@example.com" "bob@example.com"

Plain access stays strict, and a ? is still needed on each step that can be absent. The proposals in #62 to skip missing values by default, and to add !, are not taken.

Checked at 822534e with dune test --force --root .: 824 runtime and parser tests and 103 reader tests pass. Each commit's new tests were run against its parent first and failed there.

Risk: two-way door for the code; a revert restores the old ?. It is a breaking language change for users: a query that relied on ? giving null for a value of the wrong type, or on foo? hiding an undefined function, gives different output. CHANGES.md and docs/JQ_COMPATIBILITY.md describe it.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@davesnx
davesnx marked this pull request as ready for review November 9, 2026 23:50
@davesnx
davesnx merged commit 47a3bbb into main Nov 9, 2026
5 checks passed
davesnx added a commit that referenced this pull request Nov 10, 2026
* origin/main:
  Speed up interpreter hot paths and JSON rendering (#72)
  Fit the playground to the viewport and move the share button next to the query (#81)
  Make ? give no output on a type mismatch and stop hiding undefined functions (#83)
  Move .cursor documents to docs and stop tracking .cursor (#84)

# Conflicts:
#	README.md
#	cli/cli.ml
#	source/Core.ml
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

Successfully merging this pull request may close these issues.

1 participant