Skip to content

Commit e68d245

Browse files
authored
Make metaschema report exit code 2 on schema validation failure (#217)
Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent 7842cee commit e68d245

File tree

6 files changed

+11
-5
lines changed

6 files changed

+11
-5
lines changed

docs/metaschema.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ jsonschema metaschema [schemas-or-directories...]
1313
Ensure that a schema or a set of schemas are considered valid with regards to
1414
their metaschemas.
1515

16+
To help scripts distinguish validation errors, these are reported using exit
17+
code 2.
18+
1619
Examples
1720
--------
1821

src/command_metaschema.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,8 @@ auto sourcemeta::jsonschema::cli::metaschema(
6868
}
6969
}
7070

71-
return result ? EXIT_SUCCESS : EXIT_FAILURE;
71+
return result ? EXIT_SUCCESS
72+
// Report a different exit code for validation failures, to
73+
// distinguish them from other errors
74+
: 2;
7275
}

test/metaschema/fail_directory.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ cat << 'EOF' > "$TMP/schemas/schema_2.json"
2424
EOF
2525

2626
"$1" metaschema "$TMP/schemas" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?"
27-
test "$CODE" = "1" || exit 1
27+
test "$CODE" = "2" || exit 1
2828

2929
cat << EOF > "$TMP/expected.txt"
3030
fail: $(realpath "$TMP")/schemas/schema_2.json

test/metaschema/fail_single.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ cat << 'EOF' > "$TMP/schema.json"
1515
EOF
1616

1717
"$1" metaschema "$TMP/schema.json" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?"
18-
test "$CODE" = "1" || exit 1
18+
test "$CODE" = "2" || exit 1
1919

2020
cat << EOF > "$TMP/expected.txt"
2121
fail: $(realpath "$TMP")/schema.json

test/metaschema/fail_trace.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ EOF
1616

1717
"$1" metaschema "$TMP/schema.json" --trace > "$TMP/output.txt" \
1818
&& CODE="$?" || CODE="$?"
19-
test "$CODE" = "1" || exit 1
19+
test "$CODE" = "2" || exit 1
2020

2121
# Order of execution can vary
2222

test/metaschema/fail_yaml.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type: 1
1313
EOF
1414

1515
"$1" metaschema "$TMP/schema.yaml" 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?"
16-
test "$CODE" = "1" || exit 1
16+
test "$CODE" = "2" || exit 1
1717

1818
cat << EOF > "$TMP/expected.txt"
1919
fail: $(realpath "$TMP")/schema.yaml

0 commit comments

Comments
 (0)