Skip to content

fix: prevent jq parse errors in setup script#624

Merged
saddlepaddle merged 1 commit into
mainfrom
fix-jq-error
Jan 6, 2026
Merged

fix: prevent jq parse errors in setup script#624
saddlepaddle merged 1 commit into
mainfrom
fix-jq-error

Conversation

@saddlepaddle
Copy link
Copy Markdown
Collaborator

@saddlepaddle saddlepaddle commented Jan 6, 2026

Problem

The setup script was experiencing intermittent jq: parse error: Invalid numeric literal at line 1, column 8 errors when parsing neonctl CLI output.

Root cause: The 2>&1 redirects were mixing neonctl's stderr (warnings/errors) with stdout (JSON), corrupting the JSON that jq expected to parse.

Solution

Removed all 2>&1 redirects - Let neonctl work as designed: JSON on stdout, errors on stderr.

Added JSON validation - New validate_json() helper validates output before jq parsing and shows raw output on failure.

Added resilience - jq fallback syntax (.branch.id // .id // empty) handles API response variations gracefully.

Better error messages - Users see neonctl's actual errors plus contextual messages.

Changes

  • ✅ Removed 2>&1 from all neonctl commands (4 locations)
  • ✅ Added validate_json() helper function
  • ✅ Validate JSON before every jq parse
  • ✅ Added jq fallbacks for missing fields
  • ✅ Added explicit empty check for BRANCH_ID
  • ✅ Updated error messages

Benefits

  • Less brittle - stderr can't contaminate JSON output
  • Clear errors - Users see what actually failed, not cryptic jq parse errors
  • Resilient - Handles API response variations
  • Simple - No debug modes or complexity, just essential fixes

Testing

✅ Bash syntax validated with bash -n
✅ Code review of all modifications complete

The fix is backward compatible and doesn't change the script's functionality - just makes error handling more robust.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced setup process reliability with improved JSON validation and structured error reporting.
    • Clearer, more informative error messages during database branch configuration and connection string retrieval.
    • More robust output parsing with safer fallback handling for missing or malformed responses.
    • Better separation of output streams for more accurate error diagnostics.

✏️ Tip: You can customize this high-level summary in your review settings.

The setup script was experiencing intermittent "jq: parse error: Invalid
numeric literal" errors when parsing neonctl output. This was caused by
stderr contaminating stdout via 2>&1 redirects.

Changes:
- Remove 2>&1 redirects from all neonctl commands to keep JSON output clean
- Add validate_json() helper to validate output before jq parsing
- Add jq fallbacks (// empty) to handle API response variations
- Add explicit empty checks for critical values like BRANCH_ID
- Improve error messages to reference stderr output

This makes the script less brittle by letting neonctl work as designed:
JSON on stdout, errors on stderr.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 6, 2026

📝 Walkthrough

Walkthrough

A new JSON validation helper function is introduced in the Neon setup script, and the step_setup_neon_branch function is refactored to validate JSON responses, use safer jq parsing with fallback paths, separate stdout/stderr captures, and provide enhanced error messages with response structure dumps.

Changes

Cohort / File(s) Summary
Neon JSON validation and error handling
.superset/setup.sh
Added validate_json() helper to verify non-empty, valid JSON output. Refactored step_setup_neon_branch to validate JSON from list/create commands, extract branch IDs with safe fallbacks (.id // empty), separate stdout-only captures, remove stderr redirection, and enhance errors with structural dumps of responses.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 JSON now validated, nice and tight,
Fallback paths guard against the blight,
Error messages dance with helpful care,
No more stderr left floating in air!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: preventing jq parse errors in the setup script through robust JSON handling.
Description check ✅ Passed The description comprehensively covers the problem, root cause, solution, changes, benefits, and testing, fully aligning with the repository template structure.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a2417a and 6ebd8ef.

📒 Files selected for processing (1)
  • .superset/setup.sh
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-01-02T06:50:28.671Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-01-02T06:50:28.671Z
Learning: Always spin up a new Neon branch for migrations and update .env to point at the branch locally

Applied to files:

  • .superset/setup.sh
🧬 Code graph analysis (1)
.superset/setup.sh (1)
.superset/teardown.sh (1)
  • error (14-14)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Deploy Web
  • GitHub Check: Deploy API
  • GitHub Check: Deploy Admin
  • GitHub Check: Deploy Docs
  • GitHub Check: Deploy Marketing
  • GitHub Check: Build
🔇 Additional comments (4)
.superset/setup.sh (4)

28-46: LGTM! Well-designed JSON validation helper.

The function correctly validates JSON before parsing, with clear error messages and proper stderr output for debugging. Using jq empty is the idiomatic approach for JSON validation.


171-183: LGTM! Proper separation of stdout/stderr with validation.

Removing 2>&1 correctly prevents stderr from contaminating the JSON output. The validate_json call before parsing ensures jq won't fail on malformed input, and the // empty fallback handles missing fields gracefully.


191-214: LGTM! Robust branch creation with comprehensive error handling.

The fallback chain .branch.id // .id // empty handles API variations well. The debug output that pretty-prints with jq (with raw fallback) provides excellent troubleshooting information when branch ID extraction fails.


218-226: LGTM! Consistent stderr handling for connection string retrieval.

Removing 2>&1 from these commands maintains consistency with the rest of the changes and allows neonctl errors to display naturally on stderr before the error message.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 6, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch
  • ✅ Electric Fly.io app

Thank you for your contribution! 🎉

@saddlepaddle saddlepaddle merged commit 745fca8 into main Jan 6, 2026
13 checks passed
@Kitenite Kitenite deleted the fix-jq-error branch January 7, 2026 01:31
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.

1 participant