Skip to content

🌱 Use errors.AsType instead of errors.As - #3222

Merged
openshift-merge-bot[bot] merged 1 commit into
operator-framework:mainfrom
perdasilva:errors-astype
Dec 3, 2026
Merged

openshift-merge-bot[bot] merged 1 commit into
operator-framework:mainfrom
perdasilva:errors-astype

Conversation

@perdasilva

@perdasilva perdasilva commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

Go 1.26 added the generic errors.AsType, which returns the matched error and a bool:

// before
var mutErr *mutableSecretError
if errors.As(err, &mutErr) {

// after
if _, ok := errors.AsType[*mutableSecretError](err); ok {

This removes the target variables declared before each check, scopes the matched error to its if statement, and checks the target type at compile time instead of at run time (errors.As panics on an invalid target).

The change is mechanical and doesn't change behavior. It covers all 11 errors.As call sites in the repo:

  • internal/object-controller/controllers/clusterobjectset_controller.go (3)
  • internal/operator-controller/config/config.go (2)
  • internal/shared/util/http/certlog.go (1)
  • internal/shared/util/error/terminal.go (1)
  • test/internal/e2e/steps/steps.go (2), hooks.go (1), platform/steps/demo_steps.go (1)

Where the matched error isn't used, the code is _, ok := .... Otherwise the value is bound and scoped to its if statement.

I left some redundant code alone to keep this mechanical. In certlog.go, the outer errors.Unwrap loop does nothing extra, because errors.AsType already searches the whole error chain. The exitErr != nil check in hooks.go is also redundant. Either can be cleaned up in a follow-up.

Verified with make lint (0 issues) and make test-unit (pass).

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

Summary by CodeRabbit

  • Refactor
    • Updated internal error handling across application and test workflows. Existing status reporting, retry timing, command output, certificate logging, and fallback behavior remain unchanged. These changes do not alter available features or user-facing workflows. No new capabilities, configuration options, or behavior changes are included in this release.

Go 1.26 added the generic errors.AsType, which returns the matched error
and a bool. Using it removes the pre-declared target variables, scopes the
matched error to the if statement, and checks the target type at compile
time instead of at run time.

This is a mechanical change with no behavior change. It covers every
errors.As call site in the repository.

Signed-off-by: Per G. da Silva <pegoncal@redhat.com>
@netlify

netlify Bot commented Dec 2, 2026

Copy link
Copy Markdown

👷 Deploy request for olmv1 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit f5d691c

@openshift-ci
openshift-ci Bot requested review from fgiudici and pedjak December 2, 2026 09:56
@coderabbitai

coderabbitai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The changes replace errors.As pointer-target checks with typed errors.AsType calls in controller, configuration, shared utility, and end-to-end test code. Existing error handling and return behavior remain unchanged.

Changes: Typed Error Matching

Layer / File(s) Summary
Controller and configuration error matching
internal/object-controller/controllers/clusterobjectset_controller.go, internal/operator-controller/config/config.go
Controller and configuration code uses errors.AsType to extract typed errors. Existing status, retry, and formatting behavior remains unchanged.
Shared utility error matching
internal/shared/util/error/terminal.go, internal/shared/util/http/certlog.go
Terminal-reason and certificate-verification error matching uses errors.AsType. Existing return, fallback, logging, and unwrapping behavior remains unchanged.
End-to-end command error matching
test/internal/e2e/platform/steps/demo_steps.go, test/internal/e2e/steps/hooks.go, test/internal/e2e/steps/steps.go
End-to-end helpers use errors.AsType to extract command exit errors. Existing stderr handling and return behavior remain unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Suggested reviewers: pedjak, camilamacedo86, tmshort

Merge Risk: Minimal · up to f5d69

This is a mechanical error-matching refactor with no intended behavior change. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "🌱 Use errors.AsType instead of errors.As" matches the main change: all 11 errors.As call sites are migrated to the generic errors.AsType. It is specific, concise, and uses the repository's …
Description check Passed The description follows the template. It has a Description section explaining the change and motivation, with before/after code, a list of the affected files, and the verification steps. The Reviewer …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "🌱 Use errors.AsType instead of errors.As" matches the main change: all 11 errors.As call sites are migrated to the generic errors.AsType. It is specific, concise, and uses the repository's seedling prefix for an other-category change.

Full details: Description check

Explanation

The description follows the template. It has a Description section explaining the change and motivation, with before/after code, a list of the affected files, and the verification steps. The Reviewer Checklist is present. Two items are unchecked: API Go Documentation (likely not applicable, since no exported declarations change) and Links to related GitHub Issue(s), which is not provided. The author did not explain why no issue link exists.

Resolution

Optionally, add a link to a related GitHub issue or state that none exists. Optionally, state whether the API Go Documentation item applies, since the summaries report no exported declaration changes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: d43582fa-e35d-4d41-ae6b-7d7776ee268d
Commits

Reviewing files that changed from the base of the PR and between d6fb35f and f5d691c.

Files selected for processing: 7

  • internal/object-controller/controllers/clusterobjectset_controller.go
  • internal/operator-controller/config/config.go
  • internal/shared/util/error/terminal.go
  • internal/shared/util/http/certlog.go
  • test/internal/e2e/platform/steps/demo_steps.go
  • test/internal/e2e/steps/hooks.go
  • test/internal/e2e/steps/steps.go

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

@tmshort

tmshort commented Dec 2, 2026

Copy link
Copy Markdown
Member

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Dec 2, 2026
@perdasilva perdasilva added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 3, 2026
@openshift-ci

openshift-ci Bot commented Dec 3, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: rashmigottipati

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot
openshift-merge-bot Bot merged commit 65ff5e0 into operator-framework:main Dec 3, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants