← Back to Pull requests

fix(cli): improve inspect and diagnose error handling #50

Open
unknown opened this pull request with 529 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 02, 2026 17:59 UTC
Author

<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>

Diff: 529 lines (+396 / -133) across 6 files Reviewer: SakshiRRathod Review duration: 41868m
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
0.48
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 47.9% (MEDIUM) · Higher = larger blast radius
47.9%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 25.5% · Safe to merge
25.5%