tailscale/tailscale · error · HTTPError
%w: %w
Error message
%w: %w
What it means
The generic '%w: %w' wrapper used by handleError in tsweb to join the user-visible HTTPError with the underlying cause while rendering an error response. It preserves both the structured HTTP status error and the root error for the response body and logging.
Source
Thrown at tsweb/tsweb.go:806
if hs, ok := errors.AsType[HTTPStatuser](err); ok {
hErr = hs.HTTPStatus()
hAsOK = true
}
}
if hAsOK {
hOK = true
if hErr.Code == 0 {
lw.logf("[unexpected] HTTPError %v did not contain an HTTP status code, sending internal server error", hErr)
hErr.Code = http.StatusInternalServerError
}
} else if v, ok := vizerror.As(err); ok {
hErr = Error(http.StatusInternalServerError, v.Error(), nil)
} else if reqCancelled(r, err) {
// 499 is the Nginx convention meaning "Client Closed Connection".
if errors.Is(err, context.Canceled) || errors.Is(err, http.ErrAbortHandler) {
hErr = Error(499, "", err)
} else {
hErr = Error(499, "", fmt.Errorf("%w: %w", context.Canceled, err))
}
} else {
// Omit the friendly message so HTTP logs show the bare error that was
// returned and we know it's not a HTTPError.
hErr = Error(http.StatusInternalServerError, "", err)
}
// Tell the logger what error we wrote back to the client.
if pb := errCallback.Value(r.Context()); pb != nil {
pb(hErr)
logged = true
}
if r.Context().Err() != nil {
return logged
}
if lw.code != 0 {View on GitHub (pinned to 6e0912f979)
Solutions
- Unwrap with errors.Is/As to recover both the HTTPError (status code) and the root cause
- Ensure handlers wrap failures in tsweb.Error with a meaningful inner error so this join is informative
- Log the joined error for server-side diagnosis while sending the HTTPError message to the client
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at tsweb/tsweb.go:806 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tailscale/tailscale@6e0912f979 (2026-08-18).
Data as JSON: /api/errors/8f6a67f3fa4d3a11.
Report an issue: GitHub.