Fix error wrapping to preserve network error types#665
Open
maelvls wants to merge 1 commit into
Open
Conversation
Changed HTTP-related error wrapping from %v to %w to preserve underlying *url.Error and *net.OpError types. This allows consumers like cert-manager to detect network failures using errors.As(). Fixes Venafi#664 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates error wrapping in Venafi NGTS and Cloud connectors to preserve underlying errors by switching from "%w: %v" to "%w: %w" in several HTTP/request failure paths.
Changes:
- Replace string-formatting of underlying errors (
%v) with error-wrapping (%w) for request construction, execution, and response-read errors. - Apply the same wrapping pattern consistently across NGTS and Cloud implementations.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pkg/venafi/ngts/connector.go | Switches to %w for wrapping underlying errors during certificate import / token retrieval paths. |
| pkg/venafi/ngts/cloud.go | Switches to %w for wrapping underlying errors in the NGTS request helper. |
| pkg/venafi/cloud/connector.go | Switches to %w for wrapping underlying errors during certificate import / token retrieval paths. |
| pkg/venafi/cloud/cloud.go | Switches to %w for wrapping underlying errors in the Cloud request helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| statusCode, status, body, err := c.request("POST", url, request) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("%w: %v", verror.ServerTemporaryUnavailableError, err) | ||
| return nil, fmt.Errorf("%w: %w", verror.ServerTemporaryUnavailableError, err) |
| r, err := http.NewRequest(http.MethodPost, url, strings.NewReader(body.Encode())) | ||
| if err != nil { | ||
| err = fmt.Errorf("%w: %v", verror.VcertError, err) | ||
| err = fmt.Errorf("%w: %w", verror.VcertError, err) |
| resp, err := httpClient.Do(r) | ||
| if err != nil { | ||
| err = fmt.Errorf("%w: %v", verror.ServerUnavailableError, err) | ||
| err = fmt.Errorf("%w: %w", verror.ServerUnavailableError, err) |
| respBody, err := io.ReadAll(resp.Body) | ||
| if err != nil { | ||
| err = fmt.Errorf("%w: %v", verror.ServerError, err) | ||
| err = fmt.Errorf("%w: %w", verror.ServerError, err) |
e89330f to
a624e38
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.
Problem
We aren't able to distinguish the error type (e.g.,
*url.Erroror*net.OpError) when VCert returns an error during authentication. That's because the err format strings use%vinstead of%w.Solution
Very straightforward:
Fixes #664