Hi,
In Barcode Writer in Pure PostScript (BWIPP) it is possible for the user to provide invalid input data. At present we do not provide any useful form of input validation or error reporting and we simply allow the code to trip up and bomb out in meaningless ways on invalid data.
To provide a somewhat uniform approach to handling invalid user input I am investigating whether the PS code could raise a custom error and terminate for each circumstance (e.g. /bwipp.badCheckDigit or /bwipp.invalidCharacter, etc) that can be communicated to the user using whatever ordinary PS error handling is available in that environment.
So far I have a routine to customise the $error dict, invoke the handleerror procedure and quit:
/raiseerror {
$error exch /errorinfo exch put
$error exch /errorname exch put
$error /command //null put
$error /newerror true put
handleerror quit % Is quit the right thing to do here?
} bind def
...
badCheckDigitProvided {
/bwipp.badCheckDigit (Incorrect check digit provided) raiseerror
} if
This seems to work however it has the problem (at least with GhostScript) that the PS interpreter exits with a code of 0 indicating success:
$ gs
raiseerror.ps
GPL Ghostscript 9.07 (2013-02-14)
Copyright (C) 2012 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /bwipp.badCheckDigit in null
Additional information: (Incorrect check digit supplied)
Current allocation mode is local
Last OS error: No such file or directory
$ echo $?
0
Whereas a pre-defined error (in the absence of a redefined handleerror) will normally cause GhostScript to terminate with a non-zero exit code:
$ cat
bork.ps
%!PS
bork
$ gs
bork.ps
GPL Ghostscript 9.07 (2013-02-14)
Copyright (C) 2012 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /undefined in bork
<...snip stack dumps...>
Current allocation mode is local
Current file position is 11
GPL Ghostscript 9.07: Unrecoverable error, exit code 1
$ echo $?
1
Is the throwing of custom errors a sensible thing to do? It should certainly provide higher-level applications ("frontends") that wrap BWIPP with a uniform mechanism for detecting and reporting errors - by parsing stdout/stderr or using a custom handleerror.
If so, is quit the appropriate operator to cease execution? And how might I ensure that the PS interpreter exits with a non-zero exit code?
Thanks,
Terry