Skip to content

Instantly share code, notes, and snippets.

@velicanu
Created March 7, 2019 18:38
Show Gist options
  • Save velicanu/f4f2bd8a5e67a3f0c4ad7bff89f8dab7 to your computer and use it in GitHub Desktop.
Save velicanu/f4f2bd8a5e67a3f0c4ad7bff89f8dab7 to your computer and use it in GitHub Desktop.
echo Normal behavior, returns a:
echo '{}' | jq '(try (["a"]) catch null) as $selected | if $selected|length<2 then $selected[0] else "halt error" | halt_error end'
echo
echo Normal behavior, returns a:
echo '{}' | jq '(try (["a"]) catch null) as $selected | if $selected|length<2 then $selected[0] else "normal error" | error end'
echo
echo Normal behavior, returns halt error:
echo '{}' | jq '(try (["a","b"]) catch null) as $selected | if $selected|length<2 then $selected[0] else "halt error\n" | halt_error end'
echo
echo Unexpected behavior, returns null instead of "normal error":
echo '{}' | jq '(try (["a","b"]) catch null) as $selected | if $selected|length<2 then $selected[0] else ("normal error" | error) end'
echo
echo Normal behavior, returns foo:
echo '{}' | jq '(try (["a","b"]) catch null) as $selected | if $selected|length<2 then $selected[0] else "foo" end'
echo
echo Normal behavior, returns a:
echo '{}' | jq '(try (["a","b"]) catch null) as $selected | if true then $selected[0] else "normal error" | error end'
echo
echo Normal behavior, returns normal error:
echo '{}' | jq '(try (["a","b"]) catch null) as $selected | if false then $selected[0] else "normal error" | error end'
echo
echo Normal behavior, returns halt error:
echo '{}' | jq '["a","b"] as $selected | if $selected|length<2 then $selected[0] else "halt error\n" | halt_error end'
echo
echo Normal behavior, returns normal error:
echo '{}' | jq '["a","b"] as $selected | if $selected|length<2 then $selected[0] else "normal error" | error end'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment