Skip to content
Myr

Fix `foreach` non-progation of errors

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

Errors were being re-propagated as "break". Also add `error/0` builtin, which made this fix easier.

authored by Nicolas Williams · committed by Nicolas Williams · parent 46e3125 · Browse files · 2 files+16 added−6 removed
This commit

State

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

Diff stats

2 files+16 added−6 removed

  • other:+16 added−6 removed

2 files+16 added−6 removed

modified:builtin.c+1 added
957 unmodified lines
958959#define LIBM_DD(name) "def " #name ": _" #name ";",960961static const char* const jq_builtins[] = {962 "def error: error(.);",963 "def break: error(\"break\");",964 "def map(f): [.[] | f];",965 "def map_values(f): .[] |= f;",966 "def select(f): if f then . else empty end;",
211 unmodified lines
modified:compile.c+15 added-6 removed
683 unmodified lines
684 // save new state685 gen_op_bound(STOREV, state_var),686 // extract an output...687 extract,688 // ...and output it688 // ...and output it by jumping689 // past the BACKTRACK that comes690 // right after the loop body,691 // which in turn is there692 // because...693 //694 // (Incidentally, extract can also695 // backtrack, e.g., if it calls696 // empty, in which case we don't697 // get here.)698 output),699 OP_HAS_VARIABLE));700 block foreach = BLOCK(gen_op_simple(DUP),701 init,702 state_var,703 gen_op_target(FORK, loop),704 loop,696 // At this point `foreach`'s input will be on697 // top of the stack, and we don't want to output698 // it, so we backtrack.705 // ...at this point `foreach`'s original input706 // will be on top of the stack, and we don't707 // want to output it, so we backtrack.708 gen_op_simple(BACKTRACK));700 inst_set_target(output, foreach);709 inst_set_target(output, foreach); // make that JUMP go bast the BACKTRACK at the end of the loop710 block handler = gen_cond(gen_call("_equal", BLOCK(gen_lambda(gen_const(jv_string("break"))), gen_lambda(gen_noop()))),711 gen_op_simple(BACKTRACK),703 gen_call("break", gen_noop()));712 gen_call("error", gen_noop()));713 return gen_try(foreach, handler);714}715716block gen_definedor(block a, block b) {
362 unmodified lines