Skip to content

Revert "Simplify Open function by removing error check" - #3

Merged
shivang-16 merged 1 commit into
mainfrom
revert-2-shivang-16-patch-1
Aug 29, 2026
Merged

shivang-16 merged 1 commit into
mainfrom
revert-2-shivang-16-patch-1

Conversation

@shivang-16

Copy link
Copy Markdown
Owner

Reverts #2

@codeant-ai

codeant-ai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Skipping CodeAnt AI review — this PR is a revert. The diff is the inverse of code that was previously reviewed and merged, so a fresh review typically adds no signal.

If you want CodeAnt to double-check the revert, comment @codeant-ai : review and CodeAnt will start a review.

@beetle-ai

beetle-ai Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Summary by Beetle

This PR reverts a previous simplification of the PostgreSQL connection initialization function by restoring critical error handling and validation logic. The commit undoes a change that had removed essential error checks during database connection setup, connection pool configuration, and health verification. This is a defensive fix that ensures the application properly handles and reports failures during database initialization rather than silently proceeding with invalid configurations.

📁 File Changes Summary (Consolidated across all commits):

File Status Changes Description
internal/infra/postgres/postgres.go Modified +13/-2 Restored error handling in the Open() function: (1) Added error check after sql.Open() to catch connection string or driver issues; (2) Added validation for maxIdle configuration with a default fallback of 5 if not set; (3) Restored db.PingContext() call with proper error handling and cleanup to verify database connectivity before returning the client; (4) Added error handling in OpenAndMigrate() to propagate connection errors. These changes ensure the application fails fast with clear error messages rather than attempting to use an invalid database connection.

Total Changes: 1 file changed, +13 additions, -2 deletions

🎯 Key Changes:

  • Restored sql.Open() error handling: Now properly catches and wraps errors from the PostgreSQL driver initialization, preventing silent failures when the connection string is invalid or the driver is misconfigured.
  • Added maxIdle validation: Implements a safety check to ensure the idle connection pool size is at least 1, with a sensible default of 5 connections if not configured. This prevents potential connection pool exhaustion issues.
  • Restored database connectivity verification: Re-added the db.PingContext() call with a 5-second timeout to verify the database is actually reachable before returning the client. Includes proper cleanup (closing the connection) if the ping fails.
  • Improved error propagation in OpenAndMigrate(): Added explicit error handling to catch and return connection errors from the Open() function, ensuring migration failures are properly reported.
  • Better error messages: All errors are wrapped with context using fmt.Errorf(), making debugging easier by indicating exactly where the failure occurred (e.g., "open postgres", "ping postgres").
⚙️ Settings

Severity Threshold: High — Critical issues only — may miss less severe but still valuable suggestions. — Change in Settings
Custom Rules: Define your own review rules — Set Custom Rules
PR Summary: Configure PR summary — Change in Settings

📖 User Guide
  • Once repos are connected, PR analysis is automatically enabled. You can disable analysis for this repo from beetleai.dev/analysis
  • Comment @beetle on any PR to start analysis manually
  • Comment @beetle stop to stop any ongoing analysis

Follow us: Beetle · X · LinkedIn

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: da8ff497-9aa5-4949-9eb8-4c490a69d827


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.

@shivang-16
shivang-16 merged commit 1efaa1b into main Aug 29, 2026
3 checks passed
@beetle-ai

beetle-ai Bot commented Aug 29, 2026

Copy link
Copy Markdown

✅ You're good to merge this PR! No issues found. Great job!

Settings
⚙️ Settings

Severity Threshold: High — Critical issues only — may miss less severe but still valuable suggestions. — Change in Settings
Custom Rules: Define your own review rules — Set Custom Rules
PR Summary: Configure PR summary — Change in Settings

📖 User Guide
  • Once repos are connected, PR analysis is automatically enabled. You can disable analysis for this repo from beetleai.dev/analysis
  • Comment @beetle on any PR to start analysis manually
  • Comment @beetle stop to stop any ongoing analysis

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