Skip to content

fix: wrap formatted errors with %w - #1200

Open
clinta wants to merge 1 commit into
vishvananda:mainfrom
clinta:error_wrapping
Open

fix: wrap formatted errors with %w#1200
clinta wants to merge 1 commit into
vishvananda:mainfrom
clinta:error_wrapping

Conversation

@clinta

@clinta clinta commented Jul 10, 2026

Copy link
Copy Markdown

Replace formatted error wrapping that used %v with %w so callers can inspect the underlying errors with errors.Is and errors.As.

This updates error paths across address, bridge, class, devlink, link, route, and netlink namespace handling, plus the retry test helper.

Example

Previously, callers could receive an error message that included a syscall error, but the original error was flattened into text:

err := LinkSetBondSlave(link, master)
if errors.Is(err, syscall.EPERM) {
    // This would not match when EPERM was formatted with %v.
}

With %w, the wrapped error remains available to consumers:

err := LinkSetBondSlave(link, master)
if errors.Is(err, syscall.EPERM) {
    // Handle permission errors directly.
}

## Testing

- gofmt
- git diff --check
- Rescanned for remaining %v wrappers involving err, errno, or Err
- go test ./nl
- go test ./cmd/ipset-test

go test ./... does not currently complete on main because handle_retry_linux_test.go:60 calls dumpHandle.RetryInterrupted(), but Handle has no such method.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved error reporting across networking operations by preserving underlying errors for more reliable diagnosis and programmatic inspection.
* Enhanced details included with certain traffic-control parsing failures, making malformed data easier to identify.
* Maintained existing networking behavior and control flow while improving the consistency of returned errors.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 45f73b5a-4696-4f6f-acf6-8aab448a200f

📥 Commits

Reviewing files that changed from the base of the PR and between f25c7cc and 4ab26e8.

📒 Files selected for processing (7)
  • addr_linux.go
  • bridge_linux.go
  • class_linux.go
  • devlink_linux.go
  • link_linux.go
  • nl/nl_linux.go
  • route_linux.go
🚧 Files skipped from review as they are similar to previous changes (7)
  • devlink_linux.go
  • addr_linux.go
  • nl/nl_linux.go
  • class_linux.go
  • route_linux.go
  • bridge_linux.go
  • link_linux.go

📝 Walkthrough

Walkthrough

Linux networking error paths now use Go’s %w formatting across subscriptions, parsers, device operations, route handling, and namespace switching. Control flow and exported declarations remain unchanged while underlying errors become available to errors.Is and errors.As.

Changes

Linux error wrapping

Layer / File(s) Summary
Subscription callback error wrapping
addr_linux.go, link_linux.go, route_linux.go
Address, link, and route subscription callbacks now wrap receive, netlink, and parsing failures.
Parser and route encoding errors
bridge_linux.go, class_linux.go, route_linux.go
Bridge, traffic-control, and route parsing or encoding failures now preserve their underlying errors.
Device and ioctl error wrapping
devlink_linux.go, link_linux.go
TUN/TAP, devlink, bond, and veth operation errors now wrap underlying lookup, syscall, and ioctl errors.
Namespace error wrapping
nl/nl_linux.go
Network namespace lookup and switching failures now retain their underlying errors.

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 62.50% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: replacing formatted errors with %w wrapping.
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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@handle_retry_linux_test.go`:
- Line 162: In the failure return within the retry test, change the
ErrDumpInterrupted formatting in the fmt.Errorf call from %w to %v so the
timeout sentinel is described without being wrapped; preserve the existing
message and guidance text.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6ce1e738-d1d2-4774-9217-cda9c0ee3c68

📥 Commits

Reviewing files that changed from the base of the PR and between 4e35dc9 and f25c7cc.

📒 Files selected for processing (8)
  • addr_linux.go
  • bridge_linux.go
  • class_linux.go
  • devlink_linux.go
  • handle_retry_linux_test.go
  • link_linux.go
  • nl/nl_linux.go
  • route_linux.go

Comment thread handle_retry_linux_test.go Outdated
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.

1 participant