Skip to content

Fix error wrapping to preserve network error types#665

Open
maelvls wants to merge 1 commit into
Venafi:masterfrom
maelvls:fix/preserve-network-error-types
Open

Fix error wrapping to preserve network error types#665
maelvls wants to merge 1 commit into
Venafi:masterfrom
maelvls:fix/preserve-network-error-types

Conversation

@maelvls

@maelvls maelvls commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Problem

We aren't able to distinguish the error type (e.g., *url.Error or *net.OpError) when VCert returns an error during authentication. That's because the err format strings use %v instead of %w.

Solution

Very straightforward:

-err = fmt.Errorf("%w: %v", verror.ServerUnavailableError, err)
+err = fmt.Errorf("%w: %w", verror.ServerUnavailableError, err)

Fixes #664

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>
Copilot AI review requested due to automatic review settings June 11, 2026 10:53

Copilot AI 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.

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)
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.

Transport errors are not wrapped with %w, can't be matched with errors.As()

3 participants