Skip to content

Fix: handle previously ignored errors in Go backend utilities#5

Open
raznar wants to merge 3 commits intomainfrom
BugBotTest
Open

Fix: handle previously ignored errors in Go backend utilities#5
raznar wants to merge 3 commits intomainfrom
BugBotTest

Conversation

@raznar
Copy link
Owner

@raznar raznar commented Feb 25, 2026

Summary

Several places in the Go backend were silently discarding errors using the blank identifier (_ = err). This PR fixes four such locations to properly handle or surface these errors.

  • pkg/util/shortid_generator.go: Handle snowflake node initialization error instead of silently ignoring it
  • pkg/services/sqlstore/database_config.go: Check whether the password was actually set in the database URL before assigning it
  • pkg/storage/unified/resource/storage_backend.go: Propagate version-check errors through the cleanup path rather than discarding them
  • pkg/web/context.go: Log HTTP form parse errors instead of silently swallowing them

Test plan

  • Existing unit tests in pkg/util/shortid_generator_test.go pass
  • Existing integration tests in pkg/services/sqlstore/database_config_test.go pass
  • Existing tests in pkg/storage/unified/resource/storage_backend_test.go pass
  • Manual smoke test: Grafana starts and handles HTTP requests normally

Made with Cursor


Note

Medium Risk
Mostly low-impact error-handling changes, but it touches request parsing and unified storage write/cleanup paths where altered error propagation could change behavior under failure conditions.

Overview
Improves error handling and observability by removing several _ = ... patterns that previously swallowed failures.

Database URL parsing now only assigns dbCfg.Pwd when a password is actually present, web request form parsing logs ParseForm/ParseMultipartForm failures, and GenerateShortUID surfaces snowflake node init failures via stderr output.

In unified storage writes, version-check failures now attempt cleanup and return a combined error if cleanup also fails, rather than always discarding cleanup errors.

Written by Cursor Bugbot for commit 1fa29ad. This will update automatically on new commits. Configure here.

Stop discarding errors with blank identifiers in core utilities. Add proper
error checking for snowflake node initialization, database URL password
parsing, storage backend cleanup, and HTTP form parsing.

Co-authored-by: Cursor <cursoragent@cursor.com>
@raznar
Copy link
Owner Author

raznar commented Feb 25, 2026

bugbot run

if cleanupErr := k.dataStore.Delete(ctx, dataKey); cleanupErr != nil {
return 0, fmt.Errorf("cleanup failed after version check error: %w", errors.Join(err, cleanupErr))
}
// continue - cleanup succeeded, original error is cleared
Copy link

Choose a reason for hiding this comment

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

Original error silently dropped when cleanup succeeds

High Severity

When GetLatestAndPredecessor fails but Delete cleanup succeeds, the original error is silently discarded and execution continues with zero-valued latestKey/prevKey. The old code always returned an error in this case. Now, the function proceeds to use uninitialized data for optimistic concurrency checks, which could lead to incorrect version comparisons, data corruption, or silent acceptance of invalid writes.

Additional Locations (1)

Fix in Cursor Fix in Web

cursoragent and others added 2 commits February 25, 2026 15:15
The ':=' operator on line 58 created a new local 'node' variable inside
the 'if node == nil' block, shadowing the package-level 'node' declared
on line 48. This left the package-level variable permanently nil, causing
every call to GenerateShortUID to re-attempt initialization and always
fall back to UUID generation instead of using snowflake IDs.

Fix by declaring 'err' separately with 'var err error' and using '=' for
the node assignment so it writes to the package-level variable.

Co-authored-by: Ryan Aznar <ryan@aznar.io>
The condition `!set` was inverted — `userInfo.Password()` returns
`(password, set)` where `set` is true when a password is present.
Using `!set` meant `dbCfg.Pwd` was assigned only when the password
was *not* set (getting an empty string), and was skipped when a real
password existed. This effectively dropped all database passwords from
URL-based configurations.

Changed the condition to `set` and fixed the indentation of the
inner if block.

Co-authored-by: Ryan Aznar <ryan@aznar.io>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

if err != nil {
fmt.Println("failed to create snowflake node:", err)
} else if node == nil {
fmt.Println("snowflake node is nil after initialization")
Copy link

Choose a reason for hiding this comment

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

Uses fmt.Println instead of structured logger

Low Severity

Error output uses fmt.Println instead of a structured logger. The rest of the codebase (e.g., pkg/web/context.go in this same PR) uses log.New(...) for proper logging with levels, context, and structured fields. fmt.Println output goes to stdout without timestamps, log levels, or any way to filter or route it, making it inconsistent and harder to observe in production.

Fix in Cursor Fix in Web

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.

2 participants