Skip to content

CNF-23437: Wrap bare error returns for better debuggability - #6319

Open
sebrandon1 wants to merge 1 commit into
openshift-kni:mainfrom
sebrandon1:CNF-23437
Open

CNF-23437: Wrap bare error returns for better debuggability#6319
sebrandon1 wants to merge 1 commit into
openshift-kni:mainfrom
sebrandon1:CNF-23437

Conversation

@sebrandon1

@sebrandon1 sebrandon1 commented May 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Wrap 20 bare return err statements with fmt.Errorf("context: %w", err) across 5 files in controllers/ and internal/clusterconfig/
  • Fix a swallowed error in fetchIDMS where fmt.Errorf("failed to fetch IDMS") discarded the actual error -- now properly wraps with %w
  • Add 203 lines of new tests verifying wrapped error messages across all changed functions
  • No behavior change; errors use %w so errors.Is/errors.As chains are preserved

Related PRs

PR Repo Status
#3730 certsuite merged
#3633 certsuite merged
#3627 certsuite merged
#70 tls-scanner merged
#482 commatrix merged
#5180 crc merged
#946 cluster-kube-controller-manager-operator merged

Test plan

  • go build ./... compiles
  • go test ./controllers/... ./internal/clusterconfig/... all pass
  • make golangci-lint 0 issues
  • New tests assert wrapped error messages in validateAddressChanges, cleanuoUnbootedStateroots, fetchIDMS, fetchICSPs, FetchClusterConfig, FetchLvmConfig

Jira: CNF-23437 (epic: CNF-23510)

@openshift-ci-robot

openshift-ci-robot commented May 1, 2026

Copy link
Copy Markdown

@sebrandon1: This pull request references CNF-23437 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

  • Wrap 20 bare return err statements with fmt.Errorf("context: %w", err) across 5 files
  • Improves error traceability in logs — when errors surface at the controller level, the full call chain is now visible
  • No behavior change; errors are wrapped with %w so errors.Is/errors.As still work

Test plan

  • go build ./... — compiles
  • go test ./controllers/... ./internal/clusterconfig/... — all tests pass
  • make golangci-lint — 0 issues

Jira: https://redhat.atlassian.net/browse/CNF-23437

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown

Review Change Stack

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 2fe73e8e-9bd8-4132-bc6b-e19ac2e3125e

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds contextual %w-wrapped errors across IPC controller handlers and cluster configuration/LVM fetch functions. It also adds tests for address validation, cleanup failure, and configuration fetch error paths.

Changes

Error wrapping changes

Layer / File(s) Summary
Controller handler error context
controllers/ipc_config_handlers.go, controllers/ipc_idle_handlers.go, controllers/ipc_rollback_handlers.go, controllers/ipc_config_handlers_test.go, controllers/ipc_idle_handlers_test.go
IPC validation, cleanup, and rollback paths add operation-specific error context while preserving underlying errors. Tests cover address validation and cleanup failures.
Cluster configuration fetch errors
internal/clusterconfig/clusterconfig.go, internal/clusterconfig/clusterconfig_test.go
Cluster configuration, IDMS, and ICSP failures now include contextual wrapped messages. Tests cover direct and propagated fetch errors.
LVM configuration fetch errors
internal/clusterconfig/lvmconfig.go, internal/clusterconfig/lvmconfig_test.go
LVM device and local volume fetch failures are wrapped with contextual messages. Tests cover local volume serialization failure.

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

Suggested reviewers: sakhoury, sudomakeinstall2, jc-rh

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding contextual wrapping to bare error returns for improved debuggability.
Description check ✅ Passed The description explains the change, motivation, affected areas, tests, related PRs, and Jira requirement with sufficient detail.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/clusterconfig/clusterconfig.go`:
- Around line 77-78: FetchClusterConfig wraps fetchIDMS but fetchIDMS currently
drops the original error; update fetchIDMS to return a wrapped error using
fmt.Errorf with %w (e.g., fmt.Errorf("failed to fetch IDMS: %w", err)) so the
original error chain is preserved when FetchClusterConfig returns. Locate the
fetchIDMS function and replace the plain error construction that loses the root
cause with a wrapped error that includes the original err.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: dbf7ea15-a7cc-4875-9301-a649b953df30

📥 Commits

Reviewing files that changed from the base of the PR and between 8954604 and 9dad0c9.

📒 Files selected for processing (5)
  • controllers/ipc_config_handlers.go
  • controllers/ipc_idle_handlers.go
  • controllers/ipc_rollback_handlers.go
  • internal/clusterconfig/clusterconfig.go
  • internal/clusterconfig/lvmconfig.go

Comment thread internal/clusterconfig/clusterconfig.go
@sebrandon1

Copy link
Copy Markdown
Contributor Author

/retest ci/prow/ipc-e2e-flow

@sebrandon1

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@sebrandon1

Copy link
Copy Markdown
Contributor Author

/retest

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

Actionable comments posted: 0

@openshift-ci-robot

openshift-ci-robot commented Jun 16, 2026

Copy link
Copy Markdown

@sebrandon1: This pull request references CNF-23437 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

  • Wrap 20 bare return err statements with fmt.Errorf("context: %w", err) across 5 files
  • Improves error traceability in logs — when errors surface at the controller level, the full call chain is now visible
  • No behavior change; errors are wrapped with %w so errors.Is/errors.As still work

Related to

Test plan

  • go build ./... — compiles
  • go test ./controllers/... ./internal/clusterconfig/... — all tests pass
  • make golangci-lint — 0 issues

Jira: https://redhat.atlassian.net/browse/CNF-23437

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@controllers/ipc_config_handlers_test.go`:
- Around line 1431-1434: Update the error assertions at
controllers/ipc_config_handlers_test.go:1431-1434 and 1444-1447, and
internal/clusterconfig/clusterconfig_test.go:754-756, to fail immediately when
the expected error is nil before accessing err.Error(); add the appropriate test
helper/fatal nil checks, then keep each test focused on asserting the immediate
inner error details rather than only the wrapper message.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c245cdf-b6ea-48c7-b0bb-0c9383f16a69

📥 Commits

Reviewing files that changed from the base of the PR and between 75cb0ed and 590c887.

📒 Files selected for processing (7)
  • controllers/ipc_config_handlers.go
  • controllers/ipc_config_handlers_test.go
  • controllers/ipc_idle_handlers.go
  • controllers/ipc_rollback_handlers.go
  • internal/clusterconfig/clusterconfig.go
  • internal/clusterconfig/clusterconfig_test.go
  • internal/clusterconfig/lvmconfig.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • controllers/ipc_rollback_handlers.go
  • controllers/ipc_config_handlers.go
  • internal/clusterconfig/lvmconfig.go
  • controllers/ipc_idle_handlers.go

Comment thread controllers/ipc_config_handlers_test.go Outdated
@sebrandon1
sebrandon1 force-pushed the CNF-23437 branch 3 times, most recently from 08a6c3a to 1946e9b Compare August 3, 2026 16:30
@openshift-ci-robot

openshift-ci-robot commented Aug 4, 2026

Copy link
Copy Markdown

@sebrandon1: This pull request references CNF-23437 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

Summary

  • Wrap 20 bare return err statements with fmt.Errorf("context: %w", err) across 5 files in controllers/ and internal/clusterconfig/
  • Fix a swallowed error in fetchIDMS where fmt.Errorf("failed to fetch IDMS") discarded the actual error -- now properly wraps with %w
  • Add 203 lines of new tests verifying wrapped error messages across all changed functions
  • No behavior change; errors use %w so errors.Is/errors.As chains are preserved

Related PRs

PR Repo Status
#3730 certsuite merged
#3633 certsuite merged
#3627 certsuite merged
#70 tls-scanner merged
#482 commatrix merged
#5180 crc merged
#946 cluster-kube-controller-manager-operator merged

Test plan

  • go build ./... compiles
  • go test ./controllers/... ./internal/clusterconfig/... all pass
  • make golangci-lint 0 issues
  • New tests assert wrapped error messages in validateAddressChanges, cleanuoUnbootedStateroots, fetchIDMS, fetchICSPs, FetchClusterConfig, FetchLvmConfig

Jira: CNF-23437 (epic: CNF-23510)

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@sebrandon1
sebrandon1 force-pushed the CNF-23437 branch 4 times, most recently from 8d6f833 to f96218e Compare August 12, 2026 13:29

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
internal/clusterconfig/clusterconfig_test.go (1)

754-756: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Verify the error unwrap contract.

These tests only verify context text. They also pass if production code changes %w to %v. Add an errors.Unwrap assertion, or inject a sentinel client error and use assert.ErrorIs.

  • internal/clusterconfig/clusterconfig_test.go#L754-L756: Verify that the fetchIDMS error unwraps.
  • internal/clusterconfig/clusterconfig_test.go#L772-L774: Verify that the fetchICSPs error unwraps.
  • internal/clusterconfig/clusterconfig_test.go#L791-L793: Verify the nested FetchClusterConfig error chain.
  • internal/clusterconfig/lvmconfig_test.go#L228-L230: Verify that the FetchLvmConfig error unwraps.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/clusterconfig/clusterconfig_test.go` around lines 754 - 756, Update
the error-path tests to verify wrapped error identity, not only context text: in
internal/clusterconfig/clusterconfig_test.go lines 754-756 for fetchIDMS, lines
772-774 for fetchICSPs, and lines 791-793 for the nested FetchClusterConfig
chain, inject sentinel client errors and assert ErrorIs (or errors.Unwrap);
likewise update internal/clusterconfig/lvmconfig_test.go lines 228-230 for
FetchLvmConfig. Preserve the existing message assertions while confirming each
returned error unwraps to its originating sentinel.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/clusterconfig/clusterconfig_test.go`:
- Around line 754-756: Update the error-path tests to verify wrapped error
identity, not only context text: in internal/clusterconfig/clusterconfig_test.go
lines 754-756 for fetchIDMS, lines 772-774 for fetchICSPs, and lines 791-793 for
the nested FetchClusterConfig chain, inject sentinel client errors and assert
ErrorIs (or errors.Unwrap); likewise update
internal/clusterconfig/lvmconfig_test.go lines 228-230 for FetchLvmConfig.
Preserve the existing message assertions while confirming each returned error
unwraps to its originating sentinel.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ae99bd09-d7a7-4c63-9d36-ddc036195895

📥 Commits

Reviewing files that changed from the base of the PR and between 590c887 and f96218e.

📒 Files selected for processing (5)
  • controllers/ipc_config_handlers_test.go
  • controllers/ipc_idle_handlers_test.go
  • internal/clusterconfig/clusterconfig.go
  • internal/clusterconfig/clusterconfig_test.go
  • internal/clusterconfig/lvmconfig_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/clusterconfig/clusterconfig.go

@sebrandon1

Copy link
Copy Markdown
Contributor Author

/retest

@sebrandon1
sebrandon1 force-pushed the CNF-23437 branch 2 times, most recently from a626b78 to 5a6e26f Compare August 17, 2026 19:58
@sebrandon1

Copy link
Copy Markdown
Contributor Author

/retest

@sebrandon1
sebrandon1 force-pushed the CNF-23437 branch 3 times, most recently from 3e9cbb2 to 7e08193 Compare August 24, 2026 16:19
@sebrandon1
sebrandon1 force-pushed the CNF-23437 branch 3 times, most recently from bd5e067 to 4d413b9 Compare August 27, 2026 17:30
@sebrandon1

Copy link
Copy Markdown
Contributor Author

/retest

Wrap 20 bare `return err` statements with fmt.Errorf context
in controllers/ and internal/clusterconfig/ so that errors
surfacing at the controller level carry the full call chain
for easier debugging in logs.
@openshift-ci

openshift-ci Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign fontivan for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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-ci

openshift-ci Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@sebrandon1: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/ibu-e2e-flow-v6v4 46fee08 link false /test ibu-e2e-flow-v6v4
ci/prow/ibu-e2e-flow-v4v6 46fee08 link false /test ibu-e2e-flow-v4v6
ci/prow/ibu-e2e-flow 46fee08 link false /test ibu-e2e-flow
ci/prow/ipc-e2e-flow-v4v6 46fee08 link false /test ipc-e2e-flow-v4v6
ci/prow/ipc-e2e-flow-v6v4 46fee08 link false /test ipc-e2e-flow-v6v4
ci/prow/ibi-e2e-flow-v4v6 46fee08 link false /test ibi-e2e-flow-v4v6
ci/prow/ibi-e2e-flow-v6v4 46fee08 link false /test ibi-e2e-flow-v6v4
ci/prow/ipc-e2e-flow 46fee08 link true /test ipc-e2e-flow
ci/prow/ibi-e2e-flow 46fee08 link false /test ibi-e2e-flow

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants