Repository navigation
fix(coverage): handle malformed JSON root and propagate tool exit failure - #529
Merged
0xsamuel1 merged 3 commits intoOct 20, 2026
Conversation
…lure
Two regression fixes for the coverage command:
1. [Bug] handle JSON output that is empty or malformed
augment_coverage_json() previously used
which silently skipped injecting package_summaries/file_summaries/summary when
the JSON root was not an object (null, array, string, number). This meant the
command returned Ok with an empty CoverageSummary and an unaugmented output
file, giving no signal to the caller that the output was unusable.
Fixed by replacing the silent if-let with .ok_or_else(|| CliError(...))? so
any non-object root immediately returns an actionable error describing the
actual JSON type received.
2. [Bug] avoid claiming success when the coverage tool exits unsuccessfully
The run() function already checked status.success() and returned early with a
CliError on non-zero exit, but there were no focused tests verifying this
contract. Added unit and integration tests that assert the CLI exits non-zero
and emits diagnostic (never success-claiming) output for every reachable
failure path.
Unit tests added (coverage.rs mod tests):
- augment_coverage_json_rejects_non_object_root (array, null, string, number roots)
- augment_coverage_json_rejects_malformed_json (syntax errors, truncated JSON)
- validate_coverage_outputs_fails_for_malformed_json_content
- coverage_failure_message_never_claims_success
Integration tests added (crates/cli/tests/coverage.rs):
- json_output_flag_rejected_before_tool_is_spawned
- cli_never_claims_success_on_argument_validation_failure
- tool_exit_failure_is_propagated_not_swallowed
- json_format_arg_validation_guards_augmentation_path
Affected paths: crates/cli/src/commands/coverage.rs
crates/cli/tests/coverage.rs
|
@promisetechhub1788-cyber Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
[coverage]` handle JSON output that is empty or malformed
augment_coverage_json()usedif let Some(obj) = root.as_object_mut()which silently skipped injectingpackage_summaries/file_summaries/summarywhen the JSON root was not an object (e.g.null,[],"string",42). The function returnedOkwith an emptyCoverageSummaryand an unaugmented output file, giving no signal that the output was unusable.Fix: replaced the silent
if letwith.ok_or_else(|| CliError(...))so any non-object root immediately returns an actionable error describing the actual JSON type received.[coverage]` avoid claiming success when the coverage tool exits unsuccessfully
run()already checkedstatus.success()and returned early with aCliErroron non-zero exit. However, there were no focused tests verifying this contract. Added unit and integration tests that assert the CLI always exits non-zero and emits actionable (never success-claiming) stderr for every reachable failure path.Changes
crates/cli/src/commands/coverage.rsaugment_coverage_json— replaceif let Some(obj) = root.as_object_mut()with.ok_or_else(|| CliError(...))to surface unexpected root types as errorsaugment_coverage_json_rejects_non_object_rootaugment_coverage_json_rejects_malformed_jsonvalidate_coverage_outputs_fails_for_malformed_json_contentcoverage_failure_message_never_claims_successcrates/cli/tests/coverage.rsjson_output_flag_rejected_before_tool_is_spawnedcli_never_claims_success_on_argument_validation_failuretool_exit_failure_is_propagated_not_swallowedjson_format_arg_validation_guards_augmentation_pathVerification
closes #453
closes #452
closes #455
closes #454