Skip to content

Commit d48bc09

Browse files
remyluslosiusclaude
andcommitted
fix(ci): Add robust JSON validation for npm-check-updates output
Fixed jq parse error in weekly dependency audit workflow. Issue: - Workflow failing with: jq: parse error: Invalid literal at line 1, column 6 - Error occurs when ncu --jsonUpgraded outputs invalid/empty JSON Root Cause: - ncu --jsonUpgraded may output non-JSON text when no upgrades available - Direct piping to jq causes parse failures Fix: - Added JSON validation before parsing with jq - Use 'jq empty' to validate JSON before counting - Fallback to empty object {} and count=0 on any error - Proper error handling with 2>/dev/null to suppress stderr Testing: - Handles ncu success with valid JSON - Handles ncu success with invalid/empty output - Handles ncu failures gracefully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9925b0c commit d48bc09

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

.github/workflows/dependency-management.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,21 @@ jobs:
449449
echo "## Frontend Dependencies" >> audit-report.md
450450
cd frontend
451451
echo "### Outdated Packages" >> ../audit-report.md
452-
ncu --jsonUpgraded > ../frontend-outdated.json || echo "{}" > ../frontend-outdated.json
453452
454-
# Count outdated packages
455-
OUTDATED_COUNT=$(jq '. | length' ../frontend-outdated.json)
453+
# Run ncu and handle empty/invalid output
454+
if ncu --jsonUpgraded > ../frontend-outdated.json 2>&1; then
455+
# Validate JSON and count packages
456+
if jq empty ../frontend-outdated.json 2>/dev/null; then
457+
OUTDATED_COUNT=$(jq '. | length' ../frontend-outdated.json 2>/dev/null || echo "0")
458+
else
459+
echo "{}" > ../frontend-outdated.json
460+
OUTDATED_COUNT="0"
461+
fi
462+
else
463+
echo "{}" > ../frontend-outdated.json
464+
OUTDATED_COUNT="0"
465+
fi
466+
456467
echo "**$OUTDATED_COUNT packages have updates available**" >> ../audit-report.md
457468
echo "" >> ../audit-report.md
458469

0 commit comments

Comments
 (0)