1
2
3
4
5
6 package gov.nist.secauto.metaschema.cli.processor.command;
7
8 import gov.nist.secauto.metaschema.cli.processor.ExitCode;
9 import gov.nist.secauto.metaschema.cli.processor.ExitStatus;
10
11 import edu.umd.cs.findbugs.annotations.NonNull;
12
13
14
15
16 public class CommandExecutionException
17 extends Exception {
18 private final ExitCode exitCode;
19
20
21
22
23 private static final long serialVersionUID = 1L;
24
25
26
27
28
29
30
31
32 public CommandExecutionException(@NonNull ExitCode code) {
33 this.exitCode = code;
34 }
35
36
37
38
39
40
41
42
43
44
45 public CommandExecutionException(@NonNull ExitCode code, String message) {
46 super(message);
47 this.exitCode = code;
48 }
49
50
51
52
53
54
55
56
57
58
59 public CommandExecutionException(@NonNull ExitCode code, Throwable cause) {
60 super(cause);
61 this.exitCode = code;
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75 public CommandExecutionException(@NonNull ExitCode code, String message, Throwable cause) {
76 super(message, cause);
77 this.exitCode = code;
78 }
79
80
81
82
83
84
85 @NonNull
86 public ExitStatus toExitStatus() {
87 String message = getLocalizedMessage();
88
89 ExitStatus retval = message == null
90 ? exitCode.exit()
91 : exitCode.exitMessage(message);
92
93 Throwable cause = getCause();
94 if (cause != null) {
95 retval.withThrowable(cause);
96 }
97 return retval;
98 }
99 }