client: distinguish malformed request from network/server errors in Exchange#142
Open
jamiesun wants to merge 1 commit into
Open
client: distinguish malformed request from network/server errors in Exchange#142jamiesun wants to merge 1 commit into
jamiesun wants to merge 1 commit into
Conversation
Client.Exchange previously returned the bare encoding error and the underlying network error without any way to tell them apart. Callers iterating over a list of RADIUS servers could not decide whether a failure was caused by a malformed request (where trying the next server is pointless) or by a connection/server problem (where failover helps). Wrap encoding failures in a new *MalformedRequestError that unwraps to the original error. Network failures continue to be returned as-is (typically implementing net.Error), so callers can use errors.As to distinguish the two cases. Closes layeh#104 Co-authored-by: Copilot <[email protected]>
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
client.Exchange()previously returned a bareerrorfor every failure, so callers could not tell a malformed/un-encodable request apart from a network or server problem. That distinction matters for failover logic: a malformed request should not be retried against the next server, whereas a connection error should.This adds a typed
MalformedRequestError(withUnwrap) and wraps only the request-encoding failure inExchangewith it. Network errors continue to satisfynet.Error, and context errors remaincontext.DeadlineExceeded/context.Canceled, so callers can now branch cleanly:Changes
errors.go: addMalformedRequestError(Error,Unwrap) with usage doc.client.go: wrap the encode failure path; documentExchangeerror types.client_test.go: addTestClient_Exchange_malformedRequest.No behavior change for existing callers that only check
err != nil.Closes #104