CDSoft / pp

PP - Generic preprocessor (with pandoc in mind) - macros, literate programming, diagrams, scripts...

Home Page:http://cdelord.fr/pp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error messages etc.

bpj opened this issue · comments

I miss a macro to abort execution of pp if something isn't as expected:

!error(MESSAGE)

Which predictably would cause pp to print MESSAGE to stderr and exit with a non-zero exit value.

My use cases are along the lines of

!ifndef(some_macro)(
  !error(Please import some_file before importing this_file)
)

!ifdef(path_to_foo)(
  !import(!path_to_foo)
)(
  !error(Please define !raw{!}path_to_foo to contain the path to foo)
)

Or perhaps more general:

!warn[ing](MESSAGE)
!exit[(EXITVAL)]

where MESSAGE is printed to stderr
and EXITVAL defaults to 0.

Of course !error could then easily be defined by the user, but it would IMO be less confusing to have both !warning and !error as builtins.

BTW is the stderr from executing scripts and diagram processors propagated to pp's stderr or to its stdout? It seems its stdout, which is a little confusing. If I run pp from a Makefile I would like to see any errors coming from programs which pp invokes, or even that pp aborts if they exit with an error status. Perhaps an option to control this?

stderr is not redirected but the return code of the command is ignored:
scripts => stderr on stderr, stdout inserted in the document
diagrams => stderr on stderr, stdout ignored (must not interfere with pp output)
if diagrams are printed on stdout, they will be lost (they could be send to stderr).

I can add some macros (info, warning, error, exit). And redirect diagrams stdout to stderr.

Very nice feature request indeed @bpj!

I see the value of all three proposed new macros, but I also suggest that all macros that imply aborting execution should allow an optional parameter for the exit status code.

Being able to just print an error message on STDERR via !warn is useful, just as it !exiting without any message is useful too, but I think that having a single macro like !error that does both is worth it (maybe call it !abort instead, to avoid confusion with !warn).

Would it be useful to abort pp when a script or a diagram fails? (instead of just printing error messages)

Would it be useful to abort pp when a script or a diagram fails? (instead of just printing error messages)

Yes in a Makefile it's useful, since it will cause make to exit too.

Would it be useful to abort pp when a script or a diagram fails?

And in very long and time consuming build chains it would save time to abort on first error — especially during testing and development, where the whole build is run over and over again.

macros that imply aborting execution should allow an optional parameter for the exit status code.

I thought !error(0)(...) would look weird.

Done in 2.14.0 (info, warning, error, exit).