Repository navigation
feat: use new errors pkg in pkg/gameservers/ - #4691
markmandel merged 7 commits into
Conversation
Signed-off-by: Thomas Lacroix <thomas.lacroix@epitech.eu>
There was a problem hiding this comment.
Pull request overview
Migrates pkg/gameservers/* error construction/wrapping away from github.com/pkg/errors to the internal pkg/util/errors package, standardizing error prefixes by package/struct origin and updating unit tests to accommodate the new error string format.
Changes:
- Replaced
github.com/pkg/errorsusage withpkg/util/errorsacross multiple GameServer controllers and helpers, adding per-structerrshelpers (viaerrors.FromStruct) and a package-level helper (viaerrors.FromPackage). - Updated error creation/wrapping call sites to use
errs.New,errs.Errorf, anderrs.Wrap. - Relaxed several tests from exact error string equality to substring checks to avoid brittleness with the new error prefixes/wrapping format.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/gameservers/succeeded.go | Switches controller error creation/wrapping to pkg/util/errors and adds per-controller errs helper. |
| pkg/gameservers/pernodecounter.go | Uses pkg/util/errors with a per-struct errs helper for cache sync and list errors. |
| pkg/gameservers/missing.go | Switches controller error creation/wrapping to pkg/util/errors and adds per-controller errs helper. |
| pkg/gameservers/migration.go | Switches controller error creation/wrapping to pkg/util/errors and adds per-controller errs helper. |
| pkg/gameservers/health.go | Switches controller error creation/wrapping to pkg/util/errors and adds per-controller errs helper. |
| pkg/gameservers/health_test.go | Updates assertions to use substring matching for updated error messages. |
| pkg/gameservers/gameservers.go | Introduces package-level errs := errors.FromPackage() and migrates helper functions to pkg/util/errors. |
| pkg/gameservers/gameservers_test.go | Updates assertions to substring matching for updated wrapped/prefixed error messages. |
| pkg/gameservers/controller.go | Migrates controller and webhook extension error wrapping to pkg/util/errors and adds errs helpers. |
| pkg/gameservers/controller_test.go | Updates assertions to substring matching for updated wrapped/prefixed error messages. |
ðĄ Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if err != nil { | ||
| return nil, errors.WithStack(err) | ||
| return nil, err | ||
| } |
|
Build Succeeded ðĨģ Build Id: a86433ce-7bdb-4f2f-8f11-dd0fb113bb8c The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version: |
Signed-off-by: Thomas Lacroix <thomas.lacroix@epitech.eu>
Signed-off-by: Thomas Lacroix <thomas.lacroix@epitech.eu>
| // | ||
| // Wrapf returns nil if err is nil. | ||
| func (e *Errors) Wrapf(err error, format string, a ...any) error { | ||
| return e.Wrap(err, fmt.Sprintf(format, a...)) |
There was a problem hiding this comment.
Could also be
if err == nil {
return nil
}
return fmt.Errorf("%s: %w", e.prefix(fmt.Sprintf(format, a...)), err)
Might be clearer with the "prefix" part
There was a problem hiding this comment.
I think I like the nil check first - since if the error is nil, then there is no expansion of the Sprintf string - whereas in the it's current format it always gets translated.
|
Build Succeeded ðĨģ Build Id: 4030b2fa-cd67-43ef-a24d-8a8cd5885e47 The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version: |
| _, err = ext.creationValidationHandler(review) | ||
| if assert.Error(t, err) { | ||
| assert.Equal(t, `error unmarshalling GameServer json after schema validation: "WRONG DATA": json: cannot unmarshal string into Go value of type v1.GameServer`, err.Error()) | ||
| assert.Contains(t, err.Error(), `error unmarshalling GameServer json after schema validation: "WRONG DATA": json: cannot unmarshal string into Go value of type v1.GameServer`) |
There was a problem hiding this comment.
Just being nit picky on the tests ð
| assert.Contains(t, err.Error(), `error unmarshalling GameServer json after schema validation: "WRONG DATA": json: cannot unmarshal string into Go value of type v1.GameServer`) | |
| assert.ErrorContains(t, err, `error unmarshalling GameServer json after schema validation: "WRONG DATA": json: cannot unmarshal string into Go value of type v1.GameServer`) |
Same for the rest.
| if assert.Error(t, err) { | ||
| assert.Contains(t, err.Error(), v.expected.err) | ||
| } |
There was a problem hiding this comment.
| if assert.Error(t, err) { | |
| assert.Contains(t, err.Error(), v.expected.err) | |
| } | |
| require.ErrorContains(t, err, v.expected.err) |
I assume it needs to be a substring?
| // | ||
| // Wrapf returns nil if err is nil. | ||
| func (e *Errors) Wrapf(err error, format string, a ...any) error { | ||
| return e.Wrap(err, fmt.Sprintf(format, a...)) |
There was a problem hiding this comment.
I think I like the nil check first - since if the error is nil, then there is no expansion of the Sprintf string - whereas in the it's current format it always gets translated.
Signed-off-by: Thomas Lacroix <thomas.lacroix@epitech.eu>
Signed-off-by: Thomas Lacroix <thomas.lacroix@epitech.eu>
|
Build Succeeded ðĨģ Build Id: 21e2584d-b389-4e07-9fb4-5e2de52ead4a The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version: |
|
Build Succeeded ðĨģ Build Id: db694ddf-acf5-46b6-9994-9bc1b0ea0f92 The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version: |
| } | ||
|
|
||
| func TestWrapf(t *testing.T) { | ||
| sentinel := errors.New("boom") |
What type of PR is this?
/kind cleanup
What this PR does / Why we need it:
Use the new error package (https://github.com/agones-dev/agones/blob/main/pkg/util/errors/errors.go) on the pkg/gameservers/* files
Which issue(s) this PR fixes:
Work on #4510
Did you use AI tools in preparing this PR?:
Y
Special notes for your reviewer:
Many others PRs will follow
Also, not sure about the unit tests, the expected errors are fine, but matching the exact error message hmm not fully sure we want to keep that