Skip to content

Comments

feat: add Capturef#27207

Draft
gwossum wants to merge 2 commits intomaster-1.xfrom
gw/errors_capturef
Draft

feat: add Capturef#27207
gwossum wants to merge 2 commits intomaster-1.xfrom
gw/errors_capturef

Conversation

@gwossum
Copy link
Member

@gwossum gwossum commented Feb 10, 2026

Add Capturef to pkg/errors. Capturef allows including context information with the captured error messages.

Additionally, tests have been added for Capture.

CircleCI configuration has been modified to check format parameters of Capturef during CI pipeline. A .golangci.yml config file has also been added which adds the same check for golangci-lint. We do not currently use golangci-lint, but the config file has been added in case we do start using it.

Add Capturef to pkg/errors. Capturef allows including context
information with the captured error messages.

Additionally, tests have been added for Capture.

CircleCI configuration has been modified to check format parameters of
Capturef during CI pipeline. A .golangci.yml config file has also been
added which adds the same check for `golangci-lint`. We do not currently
use golangci-lint, but the config file has been added in case we do
start using it.
Copy link

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.

Pull request overview

Adds a new Capturef helper to pkg/errors to capture deferred close errors with optional formatted context, extends unit tests around error capture behavior, and updates CI/lint configuration to vet Capturef format strings.

Changes:

  • Add Capturef in pkg/errors to wrap/join close errors with optional fmt context.
  • Add comprehensive tests for Capture and Capturef behaviors and defer patterns.
  • Update CI go vet invocation and add .golangci.yml to enable printf-style checking for Capturef.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
pkg/errors/error_capture.go Introduces Capturef implementation (formatting + errors.Join) and supporting imports/doc.
pkg/errors/error_capture_test.go Adds unit tests covering Capture and Capturef behavior, including defer usage and formatting.
.circleci/config.yml Adjusts go vet invocation to treat Capturef as a printf-like function.
.golangci.yml Adds govet printf configuration for Capturef for potential future golangci-lint usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +28 to +31
// Capturef is similar to Capture but allows adding context when an error occurs.
// If an fn returns an error, then a new error is creating by concatenating ": %w"
// to fs and adding the error to the end of a.
//
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The Capturef doc comment has a few grammatical issues that make it harder to understand (e.g., “If an fn returns…”, “is creating”). Please reword for correctness/clarity so the generated GoDoc reads cleanly.

Copilot uses AI. Check for mistakes.
Comment on lines +51 to +52
func Capturef(rErr *error, fn func() error, fs string, a ...any) func() {
return func() {
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

Capturef is exported, so its parameter names show up in GoDoc and IDE tooltips. Abbreviations like fs and a are hard to interpret at call sites; consider renaming them to something like format and args for clarity.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI commented Feb 10, 2026

@gwossum I've opened a new pull request, #27208, to work on those changes. Once the pull request is ready, I'll request review from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants