Merged
Conversation
|
📊 Code Coverage Report Total Coverage: 1.8% |
Comment on lines
+47
to
+54
| h.db.Pool.QueryRow(ctx, | ||
| `SELECT COUNT(*) FROM servers WHERE "ownerId" = $1`, userID).Scan(&totalServers) | ||
| h.db.Pool.QueryRow(ctx, | ||
| `SELECT COUNT(*) FROM servers WHERE "ownerId" = $1 AND status = 'RUNNING'`, userID).Scan(&onlineServers) | ||
| h.db.Pool.QueryRow(ctx, | ||
| `SELECT COUNT(*) FROM servers WHERE "ownerId" = $1 AND status = 'OFFLINE'`, userID).Scan(&offlineServers) | ||
| h.db.Pool.QueryRow(ctx, | ||
| `SELECT COUNT(*) FROM servers WHERE "ownerId" = $1 AND "isSuspended" = true`, userID).Scan(&suspendedServers) |
There was a problem hiding this comment.
Bug: The GetDashboardStats handler ignores errors from QueryRow().Scan() calls, causing it to return a 200 OK response with misleading zero-value statistics if a database query fails.
Severity: MEDIUM
Suggested Fix
Check the error returned by each h.db.Pool.QueryRow(...).Scan(...) call in the GetDashboardStats handler. If the error is not nil, return an HTTP 500 Internal Server Error response, similar to the pattern used in the GetUserAccount handler.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: internal/handlers/dashboard.go#L47-L54
Potential issue: In the `GetDashboardStats` handler, multiple database calls using
`QueryRow().Scan()` do not have error handling. If a query fails, for instance due to a
temporary database connection issue, the error is silently ignored. As a result, the
associated variables retain their default zero values. The handler then returns an HTTP
200 OK response with misleading statistics (e.g., zero servers, zero balance), rather
than returning an appropriate server error. This behavior is inconsistent with other
handlers like `GetUserAccount` which correctly handle database errors.
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.