swipl-devel
swipl-devel copied to clipboard
Add command-line option to halt on errors/warnings
I miss an option that i could pass to swipl
, to make it stop when it encounters a warning or an error during loading of the script i passed to it on the command line.
for example:
koom@ssh_intel500 ~/h/s/data> swipl -s swipl/syntax_error.pl
ERROR: /home/koom/hackery2/src/data/swipl/syntax_error.pl:1:9: Syntax error: Unexpected end of file
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.9-14-g60891b85d-DIRTY)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.
For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).
?-
such warning or error messages can get completely lost in the surrounding output lines.
so i actually maintain a script to run swipl and check for errors before running for good: https://github.com/lodgeit-labs/FOL_solvers/blob/master/tools/dev_runner/dev_runner.pl
one other issue i ran into is that some DCG compilation errors were only printed after explicitly issuing 'make'. So my script does that too.
make/0 runs list_undefined/0 to check for undefined predicates. Not sure that is part of the "some errors"
This all sounds a little complicated to me. Why not just have a file that traps errors and makes the system halt with status 1 and either run e.g., swipl catcherrors.pl load.pl
or load catcherrors.pl
from your load.pl
. What is the use for loading all stuff while checking for errors and then load again for running?
I will consider adding a library that makes the system halt on errors. I'm not entirely sure though. There are a lot of options to consider and you typically do want the application to raise and handle exceptions without stopping.
Thanks for the explanation wrt make! I just ran into it again by luck. Anyway:
To make it clear, i'm not looking for a way to halt on unhandled exceptions or something like that.
Trapping errors sounds like it would be simpler, but that wouldn't catch warnings, at least as things are now, right? I'm talking about missing predicates, singleton variables, redefined predicates, etc. For example gcc let's you treat warnings as errors, right?
Yes loading twice is ugly. But it's saved me from missing so many important warnings.
Yeah, gcc can handle warnings as errors. In Prolog that is a little harder as we have both compiler warnings and errors and runtime warnings and errors. Also, Prolog is often used interactively which means you do not want to halt on an error, no matter which error.
Attached is a simple script that halts on the first error. That is also not ideal. Ideally I guess it should report the first N or all errors and halt as the normal execution of the program starts. It is not really clear when this happens in Prolog though. Possibly it should be integrated with library(main) or maybe initialization(Goal,main).
this looks almost good, except maybe one thing: my script can also "primitively" send a goal into swipl's stdin - into the repl. This achieves that an uncaught exception can trigger guitracer. If i invoke swipl with the -g parameter, gtrace doesn't come up. I'm aware that it's the repl's C code that does this. I would be happy if there was a way, in a catch statement, that i'd wrap around all my code, to invoke gtrace with the stack info created by library prolog_stack - but that's not how it works, right?
You can't invoke gtrace with the stack info created by library prolog_stack, at least I have no clue what that means. Maybe catch_with_backtrace/3 is what you are after?