Skip to content

Commit 9df6dff

Browse files
committed
feat: Update exit codes to be standard 0, 1, 2
1 parent 9f94677 commit 9df6dff

17 files changed

+39
-62
lines changed

src/main/java/com/endava/cats/command/CatsCommand.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,15 @@
8484
versionProvider = VersionProvider.class,
8585
commandListHeading = "%n@|bold,underline Commands:|@%n",
8686
defaultValueProvider = CommandLine.PropertiesDefaultProvider.class,
87-
exitCodeOnInvalidInput = 191,
88-
exitCodeOnExecutionException = 192,
8987
resourceBundle = "version",
9088
abbreviateSynopsis = true,
9189
synopsisHeading = "@|bold,underline Usage:|@%n",
9290
customSynopsis = {"@|bold cats|@ @|fg(yellow) -c|@ <CONTRACT> @|fg(yellow) -s|@ <SERVER> [ADDITIONAL OPTIONS]",
9391
"@|bold cats (list | replay | run | template | lint | info | stats | validate | random | generate | explain)|@ [OPTIONS]", "%n"},
9492
exitCodeListHeading = "%n@|bold,underline Exit Codes:|@%n",
9593
exitCodeList = {"@|bold 0|@:Successful program execution",
96-
"@|bold 191|@:Usage error: user input for the command was incorrect",
97-
"@|bold 192|@:Internal execution error: an exception occurred when executing command",
98-
"@|bold ERR|@:Where ERR is the number of errors reported by cats"},
94+
"@|bold 2|@:Usage error: user input for the command was incorrect",
95+
"@|bold 1|@:Internal execution error: an exception occurred when executing command"},
9996
footerHeading = "%n@|bold,underline Examples:|@%n",
10097
footer = {" Run CATS in blackbox mode and only report 500 http error codes:",
10198
" cats -c openapi.yml -s http://localhost:8080 -b -k",
@@ -263,7 +260,7 @@ public void run() {
263260
} catch (CatsException | IOException | ExecutionException | IllegalArgumentException e) {
264261
logger.fatal("Something went wrong while running CATS: {}", e.toString());
265262
logger.debug("Stacktrace: {}", e);
266-
exitCodeDueToErrors = 192;
263+
exitCodeDueToErrors = CommandLine.ExitCode.SOFTWARE;
267264
} finally {
268265
testCaseListener.endSession();
269266
}
@@ -508,7 +505,10 @@ private List<FuzzingData> filterFuzzingData(List<FuzzingData> fuzzingDataListWit
508505

509506
@Override
510507
public int getExitCode() {
511-
return exitCodeDueToErrors + executionStatisticsListener.getErrors();
508+
if (exitCodeDueToErrors > 0) {
509+
return exitCodeDueToErrors;
510+
}
511+
return executionStatisticsListener.getErrors() > 0 ? CommandLine.ExitCode.SOFTWARE : CommandLine.ExitCode.OK;
512512
}
513513

514514
@Override

src/main/java/com/endava/cats/command/ExplainCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121
name = "explain",
2222
mixinStandardHelpOptions = true,
2323
usageHelpAutoWidth = true,
24-
exitCodeOnInvalidInput = 191,
25-
exitCodeOnExecutionException = 192,
2624
exitCodeListHeading = "%n@|bold,underline Exit Codes:|@%n",
2725
exitCodeList = {"@|bold 0|@:Successful program execution",
28-
"@|bold 191|@:Usage error: user input for the command was incorrect",
29-
"@|bold 192|@:Internal execution error: an exception occurred when executing command"},
26+
"@|bold 2|@:Usage error: user input for the command was incorrect",
27+
"@|bold 1|@:Internal execution error: an exception occurred when executing command"},
3028
footerHeading = "%n@|bold,underline Examples:|@%n",
3129
footer = {" Explain a 9XX response code:",
3230
" cats explain --type response_code 953",

src/main/java/com/endava/cats/command/GenerateCommand.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@
3232
name = "generate",
3333
mixinStandardHelpOptions = true,
3434
usageHelpAutoWidth = true,
35-
exitCodeOnInvalidInput = 191,
36-
exitCodeOnExecutionException = 192,
3735
description = "Generates valid requests based on the given OpenAPI spec",
3836
exitCodeListHeading = "%n@|bold,underline Exit Codes:|@%n",
3937
exitCodeList = {"@|bold 0|@:Successful program execution",
40-
"@|bold 191|@:Usage error: user input for the command was incorrect",
41-
"@|bold 192|@:Internal execution error: an exception occurred when executing command"},
38+
"@|bold 2|@:Usage error: user input for the command was incorrect",
39+
"@|bold 1|@:Internal execution error: an exception occurred when executing command"},
4240
footerHeading = "%n@|bold,underline Examples:|@%n",
4341
footer = {" Generate payloads for a POST on /test from a given OpenAPI contract:",
4442
" cats generate -c openapi.yml -X POST -p /test",
@@ -101,7 +99,7 @@ public GenerateCommand(FuzzingDataFactory fuzzingDataFactory, CatsGlobalContext
10199
this.processingArguments = processingArguments;
102100
}
103101

104-
private int exitCodeDueToErrors = 0;
102+
private int exitCodeDueToErrors = CommandLine.ExitCode.OK;
105103

106104
@Override
107105
public void run() {
@@ -133,7 +131,7 @@ public void run() {
133131
} catch (IOException | IllegalArgumentException e) {
134132
logger.fatal("Something went wrong while running CATS: {}", e.toString());
135133
logger.debug("Stacktrace: {}", e);
136-
exitCodeDueToErrors = 192;
134+
exitCodeDueToErrors = CommandLine.ExitCode.SOFTWARE;
137135
}
138136
}
139137

src/main/java/com/endava/cats/command/InfoCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
name = "info",
1919
mixinStandardHelpOptions = true,
2020
usageHelpAutoWidth = true,
21-
exitCodeOnInvalidInput = 191,
22-
exitCodeOnExecutionException = 192,
2321
exitCodeListHeading = "%n@|bold,underline Exit Codes:|@%n",
2422
exitCodeList = {"@|bold 0|@:Successful program execution",
25-
"@|bold 191|@:Usage error: user input for the command was incorrect",
26-
"@|bold 192|@:Internal execution error: an exception occurred when executing command"},
23+
"@|bold 2|@:Usage error: user input for the command was incorrect",
24+
"@|bold 1|@:Internal execution error: an exception occurred when executing command"},
2725
footerHeading = "%n@|bold,underline Examples:|@%n",
2826
footer = {" Get info about current environment:",
2927
" cats info",

src/main/java/com/endava/cats/command/LintCommand.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,10 @@
2424
usageHelpAutoWidth = true,
2525
description = "Run OpenAPI contract linters",
2626
abbreviateSynopsis = true,
27-
exitCodeOnInvalidInput = 191,
28-
exitCodeOnExecutionException = 192,
2927
exitCodeListHeading = "%n@|bold,underline Exit Codes:|@%n",
3028
exitCodeList = {"@|bold 0|@:Successful program execution",
31-
"@|bold 191|@:Usage error: user input for the command was incorrect",
32-
"@|bold 192|@:Internal execution error: an exception occurred when executing command",
33-
"@|bold ERR|@:Where ERR is the number of errors reported by cats"},
29+
"@|bold 2|@:Usage error: user input for the command was incorrect",
30+
"@|bold 1|@:Internal execution error: an exception occurred when executing command"},
3431
footerHeading = "%n@|bold,underline Examples:|@%n",
3532
footer = {" Lint an OpenAPI contract:",
3633
" cats lint -c openapi.yml",

src/main/java/com/endava/cats/command/ListCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@
5454
name = "list",
5555
mixinStandardHelpOptions = true,
5656
usageHelpAutoWidth = true,
57-
exitCodeOnInvalidInput = 191,
58-
exitCodeOnExecutionException = 192,
5957
description = "List Fuzzers, OpenAPI paths, OpenAPI formats, Mutators, Custom Mutator Types and FieldFuzzing strategies",
6058
exitCodeListHeading = "%n@|bold,underline Exit Codes:|@%n",
6159
exitCodeList = {"@|bold 0|@:Successful program execution",
62-
"@|bold 191|@:Usage error: user input for the command was incorrect",
63-
"@|bold 192|@:Internal execution error: an exception occurred when executing command"},
60+
"@|bold 2|@:Usage error: user input for the command was incorrect",
61+
"@|bold 1|@:Internal execution error: an exception occurred when executing command"},
6462
footerHeading = "%n@|bold,underline Examples:|@%n",
6563
footer = {" List all paths for an OpenAPI contract:",
6664
" cats list --paths -c openapi.yml",

src/main/java/com/endava/cats/command/RandomCommand.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@
2727
usageHelpAutoWidth = true,
2828
description = "Run continuous fuzzing based on random mutators, rather than pre-defined fuzzers",
2929
abbreviateSynopsis = true,
30-
exitCodeOnInvalidInput = 191,
31-
exitCodeOnExecutionException = 192,
3230
synopsisHeading = "%nUsage: ",
3331
exitCodeListHeading = "%n@|bold,underline Exit Codes:|@%n",
3432
exitCodeList = {"@|bold 0|@:Successful program execution",
35-
"@|bold 191|@:Usage error: user input for the command was incorrect",
36-
"@|bold 192|@:Internal execution error: an exception occurred when executing command",
37-
"@|bold ERR|@:Where ERR is the number of errors reported by cats"},
33+
"@|bold 2|@:Usage error: user input for the command was incorrect",
34+
"@|bold 1|@:Internal execution error: an exception occurred when executing command"},
3835
footerHeading = "%n@|bold,underline Examples:|@%n",
3936
footer = {" Run continuous fuzzing for path /my-path for 100 seconds and match 500 http response codes:",
4037
" cats random -H header=value -X POST -p /my-path -s http://localhost:8080 --mc 500 --stopAfterTimeInSec 100 ",

src/main/java/com/endava/cats/command/ReplayCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@
3636
name = "replay",
3737
mixinStandardHelpOptions = true,
3838
usageHelpAutoWidth = true,
39-
exitCodeOnInvalidInput = 191,
40-
exitCodeOnExecutionException = 192,
4139
description = "Replay previously executed CATS tests",
4240
exitCodeListHeading = "%n@|bold,underline Exit Codes:|@%n",
4341
exitCodeList = {"@|bold 0|@:Successful program execution",
44-
"@|bold 191|@:Usage error: user input for the command was incorrect",
45-
"@|bold 192|@:Internal execution error: an exception occurred when executing command"},
42+
"@|bold 2|@:Usage error: user input for the command was incorrect",
43+
"@|bold 1|@:Internal execution error: an exception occurred when executing command"},
4644
footerHeading = "%n@|bold,underline Examples:|@%n",
4745
footer = {" Replay Test 1 from the default reporting folder:",
4846
" cats replay Test1",

src/main/java/com/endava/cats/command/RunCommand.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,11 @@
3131
usageHelpAutoWidth = true,
3232
description = "Run functional tests written in CATS YAML format",
3333
abbreviateSynopsis = true,
34-
exitCodeOnInvalidInput = 191,
35-
exitCodeOnExecutionException = 192,
3634
synopsisHeading = "%nUsage: ",
3735
exitCodeListHeading = "%n@|bold,underline Exit Codes:|@%n",
3836
exitCodeList = {"@|bold 0|@:Successful program execution",
39-
"@|bold 191|@:Usage error: user input for the command was incorrect",
40-
"@|bold 192|@:Internal execution error: an exception occurred when executing command",
41-
"@|bold ERR|@:Where ERR is the number of errors reported by cats"},
37+
"@|bold 2|@:Usage error: user input for the command was incorrect",
38+
"@|bold 1|@:Internal execution error: an exception occurred when executing command"},
4239
footerHeading = "%n@|bold,underline Examples:|@%n",
4340
footer = {" Run custom payloads using the SecurityFuzzer:",
4441
" cats run -c openapi.yml -s http://localhost:8080 securityFuzzer.yml",

src/main/java/com/endava/cats/command/StatsCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@
3030
name = "stats",
3131
mixinStandardHelpOptions = true,
3232
usageHelpAutoWidth = true,
33-
exitCodeOnInvalidInput = 191,
34-
exitCodeOnExecutionException = 192,
3533
description = "Prints statistics about an OpenAPI spec file",
3634
exitCodeListHeading = "%n@|bold,underline Exit Codes:|@%n",
3735
exitCodeList = {"@|bold 0|@:Successful program execution",
38-
"@|bold 191|@:Usage error: user input for the command was incorrect",
39-
"@|bold 192|@:Internal execution error: an exception occurred when executing command"},
36+
"@|bold 2|@:Usage error: user input for the command was incorrect",
37+
"@|bold 1|@:Internal execution error: an exception occurred when executing command"},
4038
footerHeading = "%n@|bold,underline Examples:|@%n",
4139
footer = {" Print stats for an OpenAPI contract:",
4240
" cats stats -c openapi.yml",

0 commit comments

Comments
 (0)