Let error(null) throw null
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.
This commit is contained in:
1 parent
3b6e7ddd72
commit
f94a9d463f
4 files changed
+4
-15
No files matched your search
@@ -1231,10 +1231,6 @@ sections:
|
|||||||
given as the argument. Errors can be caught with try/catch;
|
given as the argument. Errors can be caught with try/catch;
|
||||||
see below.
|
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:
|
examples:
|
||||||
- program: 'try error catch .'
|
- program: 'try error catch .'
|
||||||
input: '"error message"'
|
input: '"error message"'
|
||||||
|
|||||||
Generated
-3
@@ -1263,9 +1263,6 @@ jq \'[1,2,empty,3]\'
|
|||||||
.SS "error, error(message)"
|
.SS "error, error(message)"
|
||||||
Produces an error with the input value, or with the message given as the argument\. Errors can be caught with try/catch; see below\.
|
Produces an error with the input value, or with the message given as the argument\. Errors can be caught with try/catch; see below\.
|
||||||
.
|
.
|
||||||
.P
|
|
||||||
When the error value is \fBnull\fR, it produces nothing and works just like \fBempty\fR\. So \fB[null | error]\fR and \fB[error(null)]\fR both emit \fB[]\fR\.
|
|
||||||
.
|
|
||||||
.IP "" 4
|
.IP "" 4
|
||||||
.
|
.
|
||||||
.nf
|
.nf
|
||||||
|
|||||||
@@ -147,8 +147,6 @@ typedef struct {
|
|||||||
} jvp_invalid;
|
} jvp_invalid;
|
||||||
|
|
||||||
jv jv_invalid_with_msg(jv err) {
|
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));
|
jvp_invalid* i = jv_mem_alloc(sizeof(jvp_invalid));
|
||||||
i->refcnt = JV_REFCNT_INIT;
|
i->refcnt = JV_REFCNT_INIT;
|
||||||
i->errmsg = err;
|
i->errmsg = err;
|
||||||
|
|||||||
+4
-6
@@ -1270,13 +1270,11 @@ null
|
|||||||
[null,true,{"a":1}]
|
[null,true,{"a":1}]
|
||||||
[]
|
[]
|
||||||
|
|
||||||
[1,error,2]
|
.[] | try error catch .
|
||||||
|
[1,null,2]
|
||||||
|
1
|
||||||
null
|
null
|
||||||
[1,2]
|
2
|
||||||
|
|
||||||
[1,error(null),2]
|
|
||||||
0
|
|
||||||
[1,2]
|
|
||||||
|
|
||||||
try error("\($__loc__)") catch .
|
try error("\($__loc__)") catch .
|
||||||
null
|
null
|
||||||
|
|||||||
Reference in new issue
Block a user