Interface CommandExitHandler
Command
exit details, whether the command completes or is canceled. The
most common use case for implementing this interface is to process exit code, standard error or Throwable
information from the command's execution to determine whether the command "failed" or "succeeded". For "failed"
commands, implementations may throw an exception to explain the failure. When throwing an exception, implementors
are encouraged to throw exceptions derived from:
CommandCanceledException
if the commandwas canceled
in an unexpected way; for example, in response to an error during output processingCommandFailedException
if the commandexited
abnormally; for example, in response to invalid input
Note: Using a CommandErrorHandler
may affect the input received by implementations of this interface. If a
custom CommandErrorHandler
is used, no stdErr
will be received by this handler. It is expected that
any output written to standard error has already been processed by that handler and does not need to be reprocessed
by this handler.
-
Method Details
-
onCancel
void onCancel(@Nonnull String command, int exitCode, @Nullable String stdErr, @Nullable Throwable thrown) Invoked after aCommand
exits after having been canceled. Commands may be canceled by:- their
CommandErrorHandler
- their
CommandInputHandler
- their
CommandOutputHandler
- their
Future
, forAsyncCommand
PageRequest
may cancel the command when the requested page has been filled. However, it is worth noting that, to the executing command, being canceled is usually unexpected and will often result in a non-zero exit code (often13
, for theSIGPIPE
signal the command receives when the JVM closes streams to the process).- Parameters:
command
- the command that was canceledexitCode
- the exit code from the processstdErr
- any output written to standard error, if noCommandErrorHandler
is in usethrown
- any exception thrown by the handlers or the command implementation
- their
-
onExit
void onExit(@Nonnull String command, int exitCode, @Nullable String stdErr, @Nullable Throwable thrown) Invoked after aCommand
exists after running to completion without being canceled. The command may have completed successfully or failed; determining which is left to the implementation to determine.Some potential candidates for detecting failures:
- non-zero exit codes
- output written to standard error
- exceptions thrown by a handler
Multiple failure cases may be triggered at once. For example, if a command returns with a non-zero exit code, it may have written an explanation to standard error or produced other output that triggered one of the handlers to throw an exception. Prioritising or merging the possible sources of error details is left to the implementor; it is not part of the contract for this interface.
- Parameters:
command
- the command that has exitedexitCode
- the exit code from the processstdErr
- any output written to standard error, if noCommandErrorHandler
is in usethrown
- any exception thrown by the handlers or the command implementation
-