Skip to content

Better distinguish error categories using different exit codes#648

Merged
jviotti merged 9 commits intosourcemeta:mainfrom
RitoG09:fix/#153
Feb 23, 2026
Merged

Better distinguish error categories using different exit codes#648
jviotti merged 9 commits intosourcemeta:mainfrom
RitoG09:fix/#153

Conversation

@RitoG09
Copy link
Contributor

@RitoG09 RitoG09 commented Feb 5, 2026

Related to issue: sourcemeta/studio#153
Following the existing CLI convention used for exit code 2, this PR updates those cannot-start paths to return exit code 3.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 issues found across 5 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/command_validate.cc">

<violation number="1" location="src/command_validate.cc:181">
P1: Replacing `FileError` with `Fail{3}` causes the CLI to exit with code 3 but suppresses all error details (message, location, file path). The `Fail` exception type does not carry error information, and the `try_catch` handler in `src/error.h` simply returns the exit code without printing anything. This leaves the user with no indication of why the operation failed.

To fix this while keeping exit code 3, you should either:
1. Update `src/error.h` to map these `FileError` types to exit code 3 (preferred).
2. Explicitly print the error using `sourcemeta::jsonschema::print_exception` before throwing `Fail{3}`.

(Based on your team's feedback about reusing centralized error wrapper types.) [FEEDBACK_USED]</violation>
</file>

<file name="src/command_lint.cc">

<violation number="1" location="src/command_lint.cc:279">
P2: Replacing FileError wrappers with `Fail{3}` suppresses error reporting (including JSON error details and file path). `Fail` is caught only to return the exit code, so users lose the underlying schema error context entirely.</violation>
</file>

<file name="src/command_fmt.cc">

<violation number="1" location="src/command_fmt.cc:75">
P2: These schema exceptions were previously wrapped in `FileError` to preserve file path and structured error details. Replacing them with `Fail{3}` suppresses that context because `try_catch` returns the exit code without printing or serializing the error. Keep the `FileError` wrapper (and map it to exit code 3 in the central handler) so users still get file/keyword context for these failures.

(Based on your team's feedback about reusing centralized error wrapper types.) [FEEDBACK_USED]</violation>
</file>

<file name="src/command_metaschema.cc">

<violation number="1" location="src/command_metaschema.cc:51">
P2: Throwing `Fail{3}` here drops the schema dialect error details and file path, because `Fail` is handled by returning an exit code without emitting any error output. This makes the CLI fail silently (including in `--json` mode). Preserve the `FileError` wrapper or add error handling that still prints the contextual error while returning exit code 3.

(Based on your team's feedback about reusing centralized error wrapper types.) [FEEDBACK_USED]</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 6 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="src/command_lint.cc">

<violation number="1">
P1: The PR description states these paths should return exit code 3. However, `FileError` for `CompilerReferenceTargetNotSchemaError`, `SchemaKeywordError`, and `SchemaFrameError` is caught in `src/error.h` and explicitly returns `EXIT_FAILURE` (1), not 3. You must update `src/error.h` to return 3 for these error types to match the PR goal.

(Based on your team's feedback about reusing centralized error wrappers.) [FEEDBACK_USED]</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

const sourcemeta::blaze::CompilerReferenceTargetNotSchemaError
&error) {
if (printed_progress) {
std::cerr << "\n";
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: The PR description states these paths should return exit code 3. However, FileError for CompilerReferenceTargetNotSchemaError, SchemaKeywordError, and SchemaFrameError is caught in src/error.h and explicitly returns EXIT_FAILURE (1), not 3. You must update src/error.h to return 3 for these error types to match the PR goal.

(Based on your team's feedback about reusing centralized error wrappers.)

View Feedback

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/command_lint.cc, line 287:

<comment>The PR description states these paths should return exit code 3. However, `FileError` for `CompilerReferenceTargetNotSchemaError`, `SchemaKeywordError`, and `SchemaFrameError` is caught in `src/error.h` and explicitly returns `EXIT_FAILURE` (1), not 3. You must update `src/error.h` to return 3 for these error types to match the PR goal.

(Based on your team's feedback about reusing centralized error wrappers.) </comment>

<file context>
@@ -276,31 +276,37 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options)
               }
 
-              throw Fail{3};
+              throw FileError<sourcemeta::core::SchemaKeywordError>(entry.first,
+                                                                    error);
             } catch (const sourcemeta::core::SchemaFrameError &error) {
</file context>
Fix with Cubic

@RitoG09
Copy link
Contributor Author

RitoG09 commented Feb 6, 2026

Hi @jviotti need a review from you here, Should the exit code 3 remain limited to SchemaRelativeMetaschemaResolutionError, SchemaResolutionError, SchemaUnknownBaseDialectError or does it need to be extended?

Currently, these tests are failing ->
image

@jviotti
Copy link
Member

jviotti commented Feb 12, 2026

Hey @RitoG09 , sorry for the delay, lots of other stuff going on.

Should the exit code 3 remain limited to SchemaRelativeMetaschemaResolutionError, SchemaResolutionError, SchemaUnknownBaseDialectError or does it need to be extended?

I'm not sure. Maybe SchemaVocabularyError too and SchemaReferenceError, and SchemaBrokenReferenceError, and SchemaUnknownDialectError. I think collecting a finite list is tricky. What I recommend is going through the tests first instead of through the code first. By looking at every test one by one, you will see what category they apply to, and update the exit code accordingly. Then once you have the test suite properly updated, doing the code changes is trivial and you will naturally see what errors you need to catch for this.

Also there are conflicts in the PR now!

Signed-off-by: Ritabrata Ghosh <76sonali40@gmail.com>
Signed-off-by: RitoG09 <76sonali40@gmail.com>
@RitoG09
Copy link
Contributor Author

RitoG09 commented Feb 15, 2026

Hey @jviotti need your feedback here.

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti jviotti changed the title exit code 3 added Better distinguish error categories using different exit codes Feb 23, 2026
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 307 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="test/bundle/fail_invalid_id_type.sh">

<violation number="1" location="test/bundle/fail_invalid_id_type.sh:19">
P2: Missing JSON variant assertion for fail_ test case. According to team standards (learning ID: 8987a25f-4f41-4a67-914e-ada0d55918a7), failure tests should include both text and JSON variant assertions to ensure structured errors are correct and consistent. Add an equivalent test with --json flag after the text output assertion.</violation>
</file>

<file name="test/codegen/fail_invalid_schema_uri.sh">

<violation number="1" location="test/codegen/fail_invalid_schema_uri.sh:17">
P2: Failing test only validates text output; team pattern expects a `--json` variant assertion for fail_ tests. Add JSON output check for structured error consistency.</violation>
</file>

<file name="test/format/fail_extension_empty_yaml.sh">

<violation number="1" location="test/format/fail_extension_empty_yaml.sh:19">
P2: Fail test missing JSON error variant assertion. Following team convention 8987a25f, this fail_* test should include either an inline `--json` test or a companion `fail_extension_empty_yaml_json.sh` file to verify structured error output.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

test "$CODE" = "1" || exit 1
"$1" bundle "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?"
# Schema input error
test "$EXIT_CODE" = "4" || exit 1
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Missing JSON variant assertion for fail_ test case. According to team standards (learning ID: 8987a25f-4f41-4a67-914e-ada0d55918a7), failure tests should include both text and JSON variant assertions to ensure structured errors are correct and consistent. Add an equivalent test with --json flag after the text output assertion.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At test/bundle/fail_invalid_id_type.sh, line 19:

<comment>Missing JSON variant assertion for fail_ test case. According to team standards (learning ID: 8987a25f-4f41-4a67-914e-ada0d55918a7), failure tests should include both text and JSON variant assertions to ensure structured errors are correct and consistent. Add an equivalent test with --json flag after the text output assertion.</comment>

<file context>
@@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json"
-test "$CODE" = "1" || exit 1
+"$1" bundle "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?"
+# Schema input error
+test "$EXIT_CODE" = "4" || exit 1
 
 cat << EOF > "$TMP/expected.txt"
</file context>
Fix with Cubic


"$1" codegen "$TMP/schema.json" --target typescript >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
"$1" codegen "$TMP/schema.json" --target typescript >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?"
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Failing test only validates text output; team pattern expects a --json variant assertion for fail_ tests. Add JSON output check for structured error consistency.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At test/codegen/fail_invalid_schema_uri.sh, line 17:

<comment>Failing test only validates text output; team pattern expects a `--json` variant assertion for fail_ tests. Add JSON output check for structured error consistency.</comment>

<file context>
@@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json"
 
-"$1" codegen "$TMP/schema.json" --target typescript >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?"
-test "$CODE" = "1" || exit 1
+"$1" codegen "$TMP/schema.json" --target typescript >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?"
+# Schema input error
+test "$EXIT_CODE" = "4" || exit 1
</file context>
Fix with Cubic


"$1" fmt "$TMP/schemas" --extension '' 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
"$1" fmt "$TMP/schemas" --extension '' 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?"
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Fail test missing JSON error variant assertion. Following team convention 8987a25f, this fail_* test should include either an inline --json test or a companion fail_extension_empty_yaml_json.sh file to verify structured error output.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At test/format/fail_extension_empty_yaml.sh, line 19:

<comment>Fail test missing JSON error variant assertion. Following team convention 8987a25f, this fail_* test should include either an inline `--json` test or a companion `fail_extension_empty_yaml_json.sh` file to verify structured error output.</comment>

<file context>
@@ -16,8 +16,9 @@ additionalProperties: false
 
-"$1" fmt "$TMP/schemas" --extension '' 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?"
-test "$CODE" = "1" || exit 1
+"$1" fmt "$TMP/schemas" --extension '' 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?"
+# Not supported
+test "$EXIT_CODE" = "3" || exit 1
</file context>
Fix with Cubic

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@jviotti
Copy link
Member

jviotti commented Feb 23, 2026

I added a couple of commits merging main back in and splitting up the exit codes a bit more. Probably not perfect, but already good enough! Feel free to surface any oddity you see with the latest changes!

@jviotti jviotti merged commit c2690f3 into sourcemeta:main Feb 23, 2026
13 of 14 checks passed
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 307 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="test/format/fail_extension_empty_yaml.sh">

<violation number="1" location="test/format/fail_extension_empty_yaml.sh:19">
P2: Fail test lacks JSON variant assertion per team learning</violation>
</file>

<file name="test/bundle/fail_invalid_schema_uri.sh">

<violation number="1" location="test/bundle/fail_invalid_schema_uri.sh:17">
P2: Missing JSON output test variant for error case</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.


"$1" fmt "$TMP/schemas" --extension '' 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?"
test "$CODE" = "1" || exit 1
"$1" fmt "$TMP/schemas" --extension '' 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?"
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Fail test lacks JSON variant assertion per team learning

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At test/format/fail_extension_empty_yaml.sh, line 19:

<comment>Fail test lacks JSON variant assertion per team learning</comment>

<file context>
@@ -16,8 +16,9 @@ additionalProperties: false
 
-"$1" fmt "$TMP/schemas" --extension '' 2>"$TMP/stderr.txt" && CODE="$?" || CODE="$?"
-test "$CODE" = "1" || exit 1
+"$1" fmt "$TMP/schemas" --extension '' 2>"$TMP/stderr.txt" && EXIT_CODE="$?" || EXIT_CODE="$?"
+# Not supported
+test "$EXIT_CODE" = "3" || exit 1
</file context>
Fix with Cubic

@@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json"
}
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Missing JSON output test variant for error case

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At test/bundle/fail_invalid_schema_uri.sh, line 17:

<comment>Missing JSON output test variant for error case</comment>

<file context>
@@ -14,8 +14,9 @@ cat << 'EOF' > "$TMP/schema.json"
 
-"$1" bundle "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && CODE="$?" || CODE="$?"
-test "$CODE" = "1" || exit 1
+"$1" bundle "$TMP/schema.json" >"$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?"
+# Schema input error
+test "$EXIT_CODE" = "4" || exit 1
</file context>
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants