Repository navigation
fix: Correct error reporting in ResolveZone, ResolveNetworkForZone and the LB attachment path - #135
Merged
Merged
Conversation
FarnazBGH
approved these changes
Sep 15, 2026
ResolveZone appended an identical Wrapf of the GetZoneID error to retErr both before and after the metrics call, so a failure to resolve a zone by name reported the same "could not get Zone ID from <name>" message twice in the returned multierror. Keeps one append and puts the metrics call first, matching the equivalent block in ResolveNetworkForZone directly below it. No test asserted on the duplication, so nothing had pinned the behaviour. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
reconcileLBattachments' error was turned into a new error with
errors.Errorf("failed to reconcile LB attachment: %+v", err). Two problems.
Errorf does not wrap, so the original error was flattened into a string and
errors.Is and errors.As could not see through it. Any caller wanting to
match on a sentinel underneath, cloud.ErrNotFound for instance, silently
could not.
%+v on a pkg/errors value renders a full stack trace, so the returned
error's message carried that trace into the controller logs on every failed
load balancer detach.
errors.Wrap fixes both: it keeps the "failed to reconcile LB attachment:"
prefix, renders the cause without a stack trace, and implements Unwrap, so
Is and As now traverse the chain.
This was the only production call formatting an error into a new one. The
remaining %v cases are panics in envtest setup and one Info log, where
there is no error to propagate.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
ResolveNetworkForZone called the ACS error counter in the count != 1 branch of the GetNetworkByID check, where err is nil by construction. The counter ignores nil, so that call did nothing, while a genuine error from GetNetworkByID returned early without ever being counted. Moves the call into the err != nil branch. This matches both the GetNetworkByName block at the top of the same function and the GetZoneByID block in ResolveZone: count the ACS error, do not count a well-formed response that simply did not match one network. Found while fixing the duplicate append in ResolveZone; same copy-paste origin. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
hrak
force-pushed
the
fix/zone_duplicate_error
branch
from
September 15, 2026 10:05
a952c1b to
bd2111a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three small error-handling defects found while surveying
pkg/errorsusage for #133. Each is independent and in its own commit.1.
ResolveZoneappended the same error twicepkg/cloud/zone.goappended an identicalWrapfof theGetZoneIDerror toretErrboth before and after the metrics call:So a zone that could not be resolved by name reported
could not get Zone ID from <name>twice in the returned multierror. Now one append, metrics first — matching theGetNetworkByNameblock directly below it.No test asserted on the duplication, so nothing had pinned the behaviour.
2.
ResolveNetworkForZonecounted the wrong branchThe ACS error counter was called in the
count != 1branch of theGetNetworkByIDcheck, whereerris nil by construction.EvaluateErrorAndIncrementAcsReconciliationErrorCounterignores nil, so that call did nothing — while a genuine error fromGetNetworkByIDreturned early without ever being counted.Moved into the
err != nilbranch, matching both theGetNetworkByNameblock at the top of the same function and theGetZoneByIDblock inResolveZone: count the ACS error, do not count a well-formed response that simply matched no network.Effect: real ACS failures on that path now show up in
acs_reconciliation_error_count, where previously they were invisible.3. The LB attachment error was formatted, not wrapped
internal/controllers/cloudstackmachine_controller.go:214:Two problems:
Errorfdoes not wrap. The original error was flattened into a string, soerrors.Is/errors.Ascould not see through it — a caller wanting to match a sentinel underneath (cloud.ErrNotFound, say) silently could not.%+von a pkg/errors value renders a full stack trace, so the returned error's message carried that trace into the controller logs on every failed load balancer detach.pkgerrors.Wrap(err, "failed to reconcile LB attachment")fixes both: same message prefix, cause rendered without a stack trace, andWrapimplementsUnwrap(viawithStack/withMessage, pkg/errors v0.9.1), soIs/Asnow traverse the chain.This was the only production call formatting an error into a new one. The remaining
%vcases are panics in envtest setup and one Info log, where there is no error to propagate.Test plan
make buildmake lint— 0 issuesmake test— all ginkgo suites plus theinternal/controllersenvtest suite.pkg/cloud/zone_test.goasserts on the exact multierror text of both resolve paths and still passes, confirming the message shapes are unchanged apart from the removed duplicate🤖 Generated with Claude Code