Skip to content
Myr

Let error(null) throw null

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by Emanuele Torre · committed by Nico Williams · parent 3b6e7dd · Browse files · 4 files+4 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+4 added−15 removed

  • tests:+4 added−6 removed
  • other:+0 added−9 removed

4 files+4 added−15 removed

modified:docs/content/manual/manual.yml-4 removed
1229 unmodified lines
1230 Produces an error with the input value, or with the message1231 given as the argument. Errors can be caught with try/catch;1232 see below.12331234 When the error value is `null`, it produces nothing and works1235 just like `empty`. So `[null | error]` and `[error(null)]` both1236 emit `[]`.12371234 examples:1235 - program: 'try error catch .'1236 input: '"error message"'1237 output: ['"error message"']
2444 unmodified lines
modified:src/jv.c-2 removed
145 unmodified lines
146 jv errmsg;147} jvp_invalid;148149jv jv_invalid_with_msg(jv err) {150 if (JVP_HAS_KIND(err, JV_KIND_NULL))151 return JV_INVALID;150 jvp_invalid* i = jv_mem_alloc(sizeof(jvp_invalid));151 i->refcnt = JV_REFCNT_INIT;152 i->errmsg = err;153
1836 unmodified lines
modified:tests/jq.test+4 added-6 removed
1268 unmodified lines
1269[[.[]|[.a,.a]]?]1270[null,true,{"a":1}]1271[]12721273.[] | try error catch .1273[1,error,2]1274[1,null,2]127511276null1275[1,2]1277212781277[1,error(null),2]127801279[1,2]12801279try error("\($__loc__)") catch .1280null1281"{\"file\":\"<top-level>\",\"line\":1}"1282
724 unmodified lines
modified:jq.1.prebuilt-3 removed
1261 unmodified lines
1262.1263.SS "error, error(message)"1264Produces an error with the input value, or with the message given as the argument\. Errors can be caught with try/catch; see below\.1265.1266.P1267When 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\.1268.1266.IP "" 41267.1268.nf1269
2848 unmodified lines