-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c7c850
commit 3eee189
Showing
26 changed files
with
555 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...ain/java/gov/nist/secauto/metaschema/cli/processor/command/CommandExecutionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* SPDX-FileCopyrightText: none | ||
* SPDX-License-Identifier: CC0-1.0 | ||
*/ | ||
|
||
package gov.nist.secauto.metaschema.cli.processor.command; | ||
|
||
import gov.nist.secauto.metaschema.cli.processor.ExitCode; | ||
import gov.nist.secauto.metaschema.cli.processor.ExitStatus; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
/** | ||
* For use in commands to short-circut command execution. | ||
*/ | ||
public class CommandExecutionException | ||
extends Exception { | ||
private final ExitCode exitCode; | ||
|
||
/** | ||
* the serial version UID. | ||
*/ | ||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* Constructs a new exception with the provided {@code code}, and no message or | ||
* cause. | ||
* | ||
* @param code | ||
* the exit code associated with this error | ||
*/ | ||
public CommandExecutionException(@NonNull ExitCode code) { | ||
this.exitCode = code; | ||
} | ||
|
||
/** | ||
* Constructs a new exception with the provided {@code code}, {@code message}, | ||
* and no cause. | ||
* | ||
* @param code | ||
* the exit code associated with this error | ||
* @param message | ||
* the exception message | ||
*/ | ||
public CommandExecutionException(@NonNull ExitCode code, String message) { | ||
super(message); | ||
this.exitCode = code; | ||
} | ||
|
||
/** | ||
* Constructs a new exception with the no message and provided the {@code code} | ||
* and {@code cause}. | ||
* | ||
* @param code | ||
* the exit code associated with this error | ||
* @param cause | ||
* the original exception cause | ||
*/ | ||
public CommandExecutionException(@NonNull ExitCode code, Throwable cause) { | ||
super(cause); | ||
this.exitCode = code; | ||
} | ||
|
||
/** | ||
* Constructs a new exception with the provided {@code code}, {@code message}, | ||
* and {@code cause}. | ||
* | ||
* @param code | ||
* the exit code associated with this error | ||
* @param message | ||
* the exception message | ||
* @param cause | ||
* the original exception cause | ||
*/ | ||
public CommandExecutionException(@NonNull ExitCode code, String message, Throwable cause) { | ||
super(message, cause); | ||
this.exitCode = code; | ||
} | ||
|
||
/** | ||
* Generate an {@link ExitStatus} based on this exception. | ||
* | ||
* @return the exit status | ||
*/ | ||
@NonNull | ||
public ExitStatus toExitStatus() { | ||
String message = getLocalizedMessage(); | ||
|
||
ExitStatus retval = message == null | ||
? exitCode.exit() | ||
: exitCode.exitMessage(message); | ||
|
||
Throwable cause = getCause(); | ||
if (cause != null) { | ||
retval.withThrowable(cause); | ||
} | ||
return retval; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.