|
79 | 79 | ; member(Arg0, ["-g", "--goal"]) -> gather_goal(g, Args, Goals0) |
80 | 80 | ; member(Arg0, ["-f"]) -> disable_init_file |
81 | 81 | ; member(Arg0, ["--no-add-history"]) -> ignore_machine_arg |
| 82 | + ; member(Arg0, ["--halt-on-error"]) -> ignore_machine_arg |
82 | 83 | ), |
83 | 84 | !, |
84 | 85 | delegate_task(Args, Goals0) |
|
100 | 101 | write('Fast startup. Do not load initialization file (~/.scryerrc)'), nl, |
101 | 102 | write(' --no-add-history '), |
102 | 103 | write('Prevent adding input to history file (~/.scryer_history)'), nl, |
| 104 | + write(' --halt-on-error '), |
| 105 | + write('Terminate with exit code 1 on errors instead of entering REPL'), nl, |
103 | 106 | % write(' '), |
104 | 107 | halt. |
105 | 108 |
|
|
154 | 157 | Exception, |
155 | 158 | ( write_term(Goal, [variable_names(VNs),double_quotes(DQ)]), |
156 | 159 | write(' causes: '), |
157 | | - write_term(Exception, [double_quotes(DQ)]), nl % halt? |
| 160 | + write_term(Exception, [double_quotes(DQ)]), nl, |
| 161 | + ( halt_on_error_enabled -> |
| 162 | + halt(1) |
| 163 | + ; true |
| 164 | + ) |
158 | 165 | ) |
159 | 166 | ) -> true |
160 | 167 | ; write('% Warning: initialization failed for: '), |
161 | | - write_term(Goal, [variable_names(VNs),double_quotes(DQ)]), nl |
| 168 | + write_term(Goal, [variable_names(VNs),double_quotes(DQ)]), nl, |
| 169 | + ( halt_on_error_enabled -> |
| 170 | + halt(1) |
| 171 | + ; true |
| 172 | + ) |
162 | 173 | ), |
163 | 174 | run_goals(Goals). |
164 | 175 | run_goals([c(Mod)|Goals]) :- !, |
165 | | - ( catch(consult(Mod), E, print_exception(E)) -> |
| 176 | + ( catch(consult(Mod), E, (print_exception(E), (halt_on_error_enabled -> halt(1) ; true))) -> |
166 | 177 | true |
167 | 178 | ; write('% Warning: initialization failed for: '), |
168 | 179 | double_quotes_option(DQ), |
169 | | - write_term(consult(Mod), [double_quotes(DQ)]), nl |
| 180 | + write_term(consult(Mod), [double_quotes(DQ)]), nl, |
| 181 | + ( halt_on_error_enabled -> |
| 182 | + halt(1) |
| 183 | + ; true |
| 184 | + ) |
170 | 185 | ), |
171 | 186 | run_goals(Goals). |
172 | 187 | run_goals([Goal|_]) :- |
|
542 | 557 | gather_equations(Pairs, OrigVarList, Goals0) |
543 | 558 | ). |
544 | 559 |
|
| 560 | +halt_on_error_enabled :- |
| 561 | + raw_argv(Args), |
| 562 | + member("--halt-on-error", Args). |
| 563 | + |
545 | 564 | print_exception(E) :- |
546 | 565 | ( E == error('$interrupt_thrown', repl) -> nl % print the |
547 | 566 | % exception on a |
|
550 | 569 | ; true |
551 | 570 | ), |
552 | 571 | loader:write_error(E), |
553 | | - nl. |
| 572 | + nl, |
| 573 | + ( halt_on_error_enabled -> |
| 574 | + halt(1) |
| 575 | + ; true |
| 576 | + ). |
554 | 577 |
|
555 | 578 | print_exception_with_check(E) :- |
556 | 579 | ( E = error(_, _:_) -> true % if the error source contains a line |
|
0 commit comments