Skip to content

Commit

Permalink
Adding errname as a linter.
Browse files Browse the repository at this point in the history
Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error.

Also fixing one case in reverse proxy and exporting the error to allow error matching against it.

Signed-off-by: Yolan Romailler <[email protected]>
  • Loading branch information
AnomalRoil committed Dec 2, 2023
1 parent 2724188 commit 1510684
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ linters:
- dupword
- durationcheck
- errcheck
- errname
- exhaustive
- exportloopref
- gci
Expand Down
7 changes: 4 additions & 3 deletions modules/caddyhttp/reverseproxy/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func (h *Handler) proxyLoopIteration(r *http.Request, origReq *http.Request, w h
upstream := h.LoadBalancing.SelectionPolicy.Select(upstreams, r, w)
if upstream == nil {
if proxyErr == nil {
proxyErr = caddyhttp.Error(http.StatusServiceUnavailable, noUpstreamsAvailable)
proxyErr = caddyhttp.Error(http.StatusServiceUnavailable, ErrNoUpstream)
}
if !h.LoadBalancing.tryAgain(h.ctx, start, retries, proxyErr, r) {
return true, proxyErr
Expand Down Expand Up @@ -1037,7 +1037,7 @@ func (lb LoadBalancing) tryAgain(ctx caddy.Context, start time.Time, retries int
// we have to assume the upstream received the request, and
// retries need to be carefully decided, because some requests
// are not idempotent
if !isDialError && !(isHandlerError && errors.Is(herr, noUpstreamsAvailable)) {
if !isDialError && !(isHandlerError && errors.Is(herr, ErrNoUpstream)) {
if lb.RetryMatch == nil && req.Method != "GET" {
// by default, don't retry requests if they aren't GET
return false
Expand Down Expand Up @@ -1446,7 +1446,8 @@ func (c ignoreClientGoneContext) Err() error {
// from the proxy handler.
const proxyHandleResponseContextCtxKey caddy.CtxKey = "reverse_proxy_handle_response_context"

var noUpstreamsAvailable = fmt.Errorf("no upstreams available")
// ErrNoUpstream occurs when there are no upstream available.
var ErrNoUpstream = fmt.Errorf("no upstreams available")

// Interface guards
var (
Expand Down

0 comments on commit 1510684

Please sign in to comment.