Conversation
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.
There was a problem hiding this comment.
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
Capturefinpkg/errorsto wrap/join close errors with optionalfmtcontext. - Add comprehensive tests for
CaptureandCapturefbehaviors and defer patterns. - Update CI
go vetinvocation and add.golangci.ymlto enable printf-style checking forCapturef.
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.
| // 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. | ||
| // |
There was a problem hiding this comment.
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.
| func Capturef(rErr *error, fn func() error, fs string, a ...any) func() { | ||
| return func() { |
There was a problem hiding this comment.
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.
fa5c0aa to
dea1148
Compare
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.