public 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 command
was canceled
in an unexpected way; for example, in response
to an error during output processingCommandFailedException
if the command
exited
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.
Modifier and Type | Method and Description |
---|---|
void |
onCancel(String command,
int exitCode,
String stdErr,
Throwable thrown)
Invoked after a
Command exits after having been canceled. |
void |
onExit(String command,
int exitCode,
String stdErr,
Throwable thrown)
Invoked after a
Command exists after running to completion without being canceled. |
void onCancel(@Nonnull String command, int exitCode, @Nullable String stdErr, @Nullable Throwable thrown)
Command
exits after having been canceled. Commands may be canceled by:
CommandErrorHandler
CommandInputHandler
CommandOutputHandler
Future
, for AsyncCommand
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 (often 13
, for the SIGPIPE
signal the
command receives when the JVM closes streams to the process).command
- the command that was canceledexitCode
- the exit code from the processstdErr
- any output written to standard error, if no CommandErrorHandler
is in usethrown
- any exception thrown by the handlers or the command implementationvoid onExit(@Nonnull String command, int exitCode, @Nullable String stdErr, @Nullable Throwable thrown)
Command
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:
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.
command
- the command that has exitedexitCode
- the exit code from the processstdErr
- any output written to standard error, if no CommandErrorHandler
is in usethrown
- any exception thrown by the handlers or the command implementationCopyright © 2019 Atlassian. All rights reserved.