3
votes

Is there a way to make SWI Prolog exit on any syntax or parse errors? I'm writing tests and running them automatically, and I don't always notice the error messages if I have syntax errors.

1

1 Answers

2
votes

Assuming you mean source file compilation errors, the load_files/2 predicate misses an option to stop on first error. A possible solution is to define the message_hook/3 predicate to call abort/0 or halt/1 in the case of a syntax error. Something like:

:- multifile user:message_hook/3.

user:message_hook(syntax_error(Culprit), _, _) :-
    % maybe print Culprit for some debugging information
    abort.