Skip to content

feat: use new errors pkg in pkg/gameservers/ - #4691

Merged
markmandel merged 7 commits into
agones-dev:mainfrom
lacroixthomas:features/integrate-errors-gameservers-pkg
Aug 29, 2026
Merged

markmandel merged 7 commits into
agones-dev:mainfrom
lacroixthomas:features/integrate-errors-gameservers-pkg

Conversation

@lacroixthomas

@lacroixthomas lacroixthomas commented Aug 18, 2026 •

Copy link
Copy Markdown
Collaborator

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

Signed-off-by: Thomas Lacroix <thomas.lacroix@epitech.eu>
@github-actions github-actions Bot added kind/cleanup Refactoring code, fixing up documentation, etc size/M labels Aug 18, 2026
@lacroixthomas
lacroixthomas requested a lite review from Copilot August 18, 2026 22:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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/errors usage with pkg/util/errors across multiple GameServer controllers and helpers, adding per-struct errs helpers (via errors.FromStruct) and a package-level helper (via errors.FromPackage).
  • Updated error creation/wrapping call sites to use errs.New, errs.Errorf, and errs.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.

Comment on lines 630 to 632
if err != nil {
return nil, errors.WithStack(err)
return nil, err
}
@lacroixthomas
lacroixthomas marked this pull request as ready for review August 18, 2026 22:20
@lacroixthomas
lacroixthomas requested a review from a team August 18, 2026 22:21
@agones-bot

Copy link
Copy Markdown
Collaborator

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:

git fetch https://github.com/googleforgames/agones.git pull/4691/head:pr_4691 && git checkout pr_4691
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.61.0-dev-24c4f36

Comment thread pkg/gameservers/controller.go Outdated
Signed-off-by: Thomas Lacroix <thomas.lacroix@epitech.eu>
Signed-off-by: Thomas Lacroix <thomas.lacroix@epitech.eu>
Comment thread pkg/util/errors/errors.go Outdated
//
// 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...))

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.

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

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.

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.

@agones-bot

Copy link
Copy Markdown
Collaborator

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:

git fetch https://github.com/googleforgames/agones.git pull/4691/head:pr_4691 && git checkout pr_4691
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.61.0-dev-f18deb0

Comment thread pkg/gameservers/controller_test.go Outdated
_, 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`)

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.

Just being nit picky on the tests 😄

Suggested change
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.

Comment thread pkg/gameservers/health_test.go Outdated
Comment on lines +253 to +255
if assert.Error(t, err) {
assert.Contains(t, err.Error(), v.expected.err)
}

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.

Suggested change
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?

Comment thread pkg/util/errors/errors.go Outdated
//
// 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...))

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.

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.

lacroixthomas and others added 3 commits August 24, 2026 17:09
Signed-off-by: Thomas Lacroix <thomas.lacroix@epitech.eu>
Signed-off-by: Thomas Lacroix <thomas.lacroix@epitech.eu>
@agones-bot

Copy link
Copy Markdown
Collaborator

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:

git fetch https://github.com/googleforgames/agones.git pull/4691/head:pr_4691 && git checkout pr_4691
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.61.0-dev-c661982

@agones-bot

Copy link
Copy Markdown
Collaborator

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:

git fetch https://github.com/googleforgames/agones.git pull/4691/head:pr_4691 && git checkout pr_4691
helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.61.0-dev-99fa4dc

}

func TestWrapf(t *testing.T) {
sentinel := errors.New("boom")

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.

boom.

@markmandel
markmandel merged commit 1cc6f54 into agones-dev:main Aug 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Refactoring code, fixing up documentation, etc size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants