Skip to content

Commit

Permalink
Let error(null) throw null
Browse files Browse the repository at this point in the history
This patch removes the weird behaviour of jv_invalid_with_msg(jv_null())
that returns jv_invalid() (i.e. empty), instead of a boxed jv_null().

The previous behaviour of  null|error  was obviously unintentional, and
allowing is jv_invalid_with_msg() to return values on which you can't
call jv_invalid_get_msg() is only error prone.
  • Loading branch information
emanuele6 committed Aug 4, 2023
1 parent 3b6e7dd commit 358c013
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 15 deletions.
4 changes: 0 additions & 4 deletions docs/content/manual/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1231,10 +1231,6 @@ sections:
given as the argument. Errors can be caught with try/catch;
see below.
When the error value is `null`, it produces nothing and works
just like `empty`. So `[null | error]` and `[error(null)]` both
emit `[]`.
examples:
- program: 'try error catch .'
input: '"error message"'
Expand Down
3 changes: 0 additions & 3 deletions jq.1.prebuilt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/jv.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ typedef struct {
} jvp_invalid;

jv jv_invalid_with_msg(jv err) {
if (JVP_HAS_KIND(err, JV_KIND_NULL))
return JV_INVALID;
jvp_invalid* i = jv_mem_alloc(sizeof(jvp_invalid));
i->refcnt = JV_REFCNT_INIT;
i->errmsg = err;
Expand Down
10 changes: 4 additions & 6 deletions tests/jq.test
Original file line number Diff line number Diff line change
Expand Up @@ -1270,13 +1270,11 @@ null
[null,true,{"a":1}]
[]

[1,error,2]
.[] | try error catch .
[1,null,2]
1
null
[1,2]

[1,error(null),2]
0
[1,2]
2

try error("\($__loc__)") catch .
null
Expand Down

0 comments on commit 358c013

Please sign in to comment.