Skip to content

fix(repos/postgres): return empty slice instead of nil when no databases found#486

Open
poyrazK wants to merge 1 commit intomainfrom
fix/cli-db-list-null-response
Open

fix(repos/postgres): return empty slice instead of nil when no databases found#486
poyrazK wants to merge 1 commit intomainfrom
fix/cli-db-list-null-response

Conversation

@poyrazK
Copy link
Copy Markdown
Owner

@poyrazK poyrazK commented May 7, 2026

Summary

Fixes cloud db list returning null in JSON mode when no databases exist, instead of [].

Changes

Changed scanDatabases in internal/repositories/postgres/database_repo.go to initialize the slice with make() instead of var:

// Before: var databases []*domain.Database  // nil when no rows
// After:  databases := make([]*domain.Database, 0)  // [] when no rows

Root Cause

When Go's encoding/json marshals a nil slice, it produces null. An empty initialized slice produces [].

Test Plan

  • go build ./internal/repositories/postgres/... — passes
  • go test -v ./internal/repositories/postgres/... — all tests pass

Fixes

Fixes #459

…ses found

When scanDatabases returns nil (no rows), JSON marshal produces "null"
instead of "[]". Initialize the slice with make() so empty results marshal
as empty array.

Fixes #459
Copilot AI review requested due to automatic review settings May 7, 2026 18:13
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Warning

Rate limit exceeded

@poyrazK has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 21 seconds before requesting another review.

To continue reviewing without waiting, purchase usage credits in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1b628ca0-81ac-4dc2-b50c-99637341a0a6

📥 Commits

Reviewing files that changed from the base of the PR and between 5faabcc and 7e46d52.

📒 Files selected for processing (1)
  • internal/repositories/postgres/database_repo.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/cli-db-list-null-response

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

CLI db list returns null in JSON mode instead of empty array

2 participants