Skip to content

CBG-5969 gopls: use fmt.Errorf vs errors.New - #8499

Merged
bbrks merged 4 commits into
mainfrom
CBG-5969-gopls-errorf
Aug 5, 2026
Merged

bbrks merged 4 commits into
mainfrom
CBG-5969-gopls-errorf

Conversation

@torcolvin

Copy link
Copy Markdown
Collaborator

CBG-5969 gopls: use fmt.Errorf vs errors.New and use string literal for regex.

Copilot AI review requested due to automatic review settings July 30, 2026 23:36
@factory-droid

factory-droid Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Droid finished @torcolvin's task —— View job


Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not ready to approve

Enabling S1028 will fail lint due to remaining errors.New(fmt.Sprintf(...)) violations (e.g., in base/logger_file.go), and one updated error message string in base/bucket.go is currently malformed/confusing.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.

Pull request overview

This PR applies Go linter-driven cleanups across Sync Gateway’s codebase by simplifying error construction (using fmt.Errorf) and simplifying a regular expression literal, and then updates the strict golangci configuration to stop excluding the corresponding staticcheck rule.

Changes:

  • Replace errors.New(fmt.Sprintf(...)) with fmt.Errorf(...) in several call sites.
  • Convert the HTTP range regex to a raw string literal to avoid double-escaping.
  • Remove the .golangci-strict.yml exclusion for staticcheck S1028.
File summaries
File Description
rest/server_context.go Simplifies an “unknown event handler type” error to use fmt.Errorf.
rest/handler.go Uses a raw string literal for the byte-range regex to match staticcheck guidance.
base/leaky_datastore.go Simplifies artificial leaky-bucket error construction with fmt.Errorf.
base/bucket.go Simplifies error construction when the mgmt request returns a non-200 status.
.golangci-strict.yml Enables S1028 by removing its exclusion from the strict linter config.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 2
  • Review effort level: Lite

We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.

Comment thread base/bucket.go Outdated
Comment thread .golangci-strict.yml Outdated
Comment thread .golangci-strict.yml
Comment thread base/bucket.go Outdated

@factory-droid factory-droid Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Enabling staticcheck S1028 is a good cleanup, but there are still S1028 violations elsewhere in the repo that will likely break strict lint. There is also a small, user-visible error-string typo in base/bucket.go that is easy to correct while touching this area.

torcolvin and others added 2 commits July 31, 2026 10:42
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@torcolvin
torcolvin requested a review from bbrks July 31, 2026 14:55
Comment thread base/bucket.go Outdated
WarnfCtx(ctx, "403 Forbidden attempting to access %s. Bucket user must have Bucket Full Access and Bucket Admin roles to retrieve metadata purge interval.", UD(uri))
} else if statusCode != http.StatusOK {
return 0, errors.New(fmt.Sprintf("failed with status code, %d, statusCode", statusCode))
return 0, fmt.Errorf("failed to retrieve purge interval from %s: status code %d", UD(uri), statusCode)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

fmt.Errorf won't redact but I'm not convinced it needs to be part of the error anyway - the caller knows what bucket it is which is probably the only relevant part of URI

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think this is pretty unlikely to fail but I added base.RedactErrorf if it shows up in logging and otherwise it gets returned to a user.

@bbrks bbrks assigned torcolvin and unassigned bbrks Jul 31, 2026
@torcolvin
torcolvin requested review from a team and bbrks August 4, 2026 18:25
@torcolvin torcolvin assigned bbrks and unassigned torcolvin Aug 4, 2026
@bbrks
bbrks merged commit bb2b358 into main Aug 5, 2026
48 checks passed
@bbrks
bbrks deleted the CBG-5969-gopls-errorf branch August 5, 2026 16:32
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.

3 participants