fix(cli): improve inspect and diagnose error handling #50
All Vouch review confidence checks passed
Residual risk 0.26 = Change Risk (0.48) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 529 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.375
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #50"
general
weight: 0.35
SakshiRRathod
<h3>Overview</h3>
<p>
This PR improves the error handling and testability of DataQuarry's
<code>inspect</code> and <code>diagnose</code> CLI commands. It ensures
that command failures are reported with meaningful contextual information
and strengthens test coverage for invalid input scenarios.
</p>
<p>
The changes also refactor the diagnostic execution logic into a dedicated
function, making the command easier to test and maintain without altering
the core diagnostic analysis behavior.
</p>
<h3>Problem Statement</h3>
<p>
Previously, the diagnostic command's execution logic was embedded directly
within the Cobra command's <code>RunE</code> callback. This made the
command's behavior less straightforward to test independently.
</p>
<p>
Additionally, invalid input scenarios such as missing files, invalid
Parquet files, and directory paths required consistent error handling
and validation to ensure users receive useful feedback instead of
ambiguous failures.
</p>
<h3>Changes Implemented</h3>
<h4>1. Refactored Diagnose Command Execution</h4>
<ul>
<li>Extracted the diagnostic execution logic into a dedicated <code>runDiagnose</code> function.</li>
<li>Updated the Cobra command to use <code>runDiagnose</code> as its <code>RunE</code> handler.</li>
<li>Improved separation between CLI command configuration and execution logic.</li>
<li>Enhanced testability and maintainability of the diagnose command.</li>
</ul>
<h4>2. Preserved Diagnostic Analysis Workflow</h4>
<ul>
<li>Preserved the existing diagnostic analysis workflow, including:
<ul>
<li>High null-ratio detection.</li>
<li>Small row-group detection.</li>
<li>Severity classification.</li>
<li>Evidence generation.</li>
<li>Recommendation output.</li>
</ul>
</li>
<li>Maintained the existing <code>No diagnostic findings.</code> message when no issues are detected.</li>
</ul>
<h4>3. Strengthened Error Handling</h4>
<ul>
<li>Preserved contextual error wrapping using <code>fmt.Errorf</code> and <code>%w</code>.</li>
<li>Ensured errors retain the command context (<code>diagnose</code> or <code>inspect</code>) alongside the underlying Parquet processing error.</li>
<li>Added test coverage for directory paths supplied as input to both commands.</li>
<li>Verified that invalid inputs return errors instead of being treated as successful operations.</li>
</ul>
<h4>4. Expanded Test Coverage</h4>
<ul>
<li><code>TestRunDiagnoseDirectoryInput</code>
<ul>
<li>Verifies that passing a directory to the diagnose command returns an error.</li>
<li>Confirms that the error contains the diagnose command context.</li>
</ul>
</li>
<li><code>TestRunInspectDirectoryInput</code>
<ul>
<li>Verifies that passing a directory to the inspect command returns an error.</li>
<li>Confirms that the error contains the inspect command context.</li>
</ul>
</li>
<li>Added subprocess-level testing to verify that CLI failures return a non-zero exit status.</li>
<li>Verified that subprocess error output contains the relevant directory path.</li>
<li>Existing tests continue to validate successful command execution, missing-file errors, invalid Parquet files, argument validation, and diagnostic findings.</li>
</ul>
<h3>Testing and Validation</h3>
<p>The following validation commands were executed successfully:</p>
<ul>
<li><code>go test ./...</code> — Passed</li>
<li><code>go test -race ./...</code> — Passed</li>
<li><code>go vet ./...</code> — Passed</li>
<li><code>go build ./...</code> — Passed</li>
<li><code>git diff --check</code> — Passed</li>
</ul>
<h3>Impact</h3>
<ul>
<li>Improves clarity and consistency of CLI error reporting.</li>
<li>Makes diagnostic execution easier to test independently.</li>
<li>Strengthens robustness when users provide invalid filesystem inputs.</li>
<li>Maintains existing Parquet inspection and diagnostic functionality.</li>
<li>Introduces no changes to the underlying diagnostic rules or metadata extraction logic.</li>
</ul>
<h3>Related Issue</h3>
<p>Closes #24</p>