Command Process Boundaries #
Helpers for reporting pure parser failures through an executable's IO boundary.
Lift a parser result into IO, prefixing failures with the executable name.
Several of the shared parsers take exeName themselves and have already named the program in their
message, takePositiveNatFlag among them. Prefixing again gives
quickstart_mlp: quickstart_mlp: --steps must be > 0, so the name is only added when it is not
there yet. Deciding that here rather than at every call site is what lets one parse function mix
the two parser styles without the caller having to remember which is which.
Instances For
Run an executable's entry point and report a failure the way a command-line tool should.
Every parser above refuses bad input by throwing an IO error, which is the right thing for the
parser to do. Left alone, that error escapes main and the Lean runtime prints it as
uncaught exception: quickstart_mlp: --steps must be > 0, which reads like a crash in the middle
of a run even though the program rejected the command line on purpose. This wrapper catches the
error at the last possible moment, prints it as error: … on stderr, and returns exit status 1.
The status is what the runtime would have produced anyway; only the wording changes.