inancgumus/learngo · error
signature doesn't match, got: % x, want: % x
Error message
signature doesn't match, got: % x, want: % x
What it means
signatureReader.Read verifies that the first bytes of the wrapped stream (e.g. an HTTP response body) match an expected signature; on the first Read, if the prefix bytes differ, Read returns this error instead of the underlying reader's. The got/want values are hex-dumped byte slices limited to the signature length (or buffer length if smaller). Once matched, the signature buffer is cleared and streaming continues transparently.
Source
Thrown at interfaces/17-write-an-io-reader/reader.go:41
// Read implements the io.Reader interface.
func (sr *signatureReader) Read(b []byte) (n int, err error) {
n, err = sr.r.Read(b)
l := len(sr.signature)
if l == 0 {
// simply return if the signature has already been detected.
return
}
if lb := len(b); lb < l {
l = lb
}
if got, want := b[:l], sr.signature[:l]; !bytes.Equal(got, want) {
err = fmt.Errorf("signature doesn't match, got: % x, want: % x", got, want)
}
sr.signature = nil // or similar clearing in the full source
return
}View on GitHub (pinned to 3c475a78e5)
Solutions
- Compare the got/want hex dumps to identify the actual content type and adjust the expected signature.
- Treat the error as a content-type mismatch: close/discard the stream and report it to the caller.
- Validate the resource's Content-Type header before wrapping it with signatureReader.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at interfaces/17-write-an-io-reader/reader.go:41 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of inancgumus/learngo@3c475a78e5 (2026-09-02).
Data as JSON: /api/errors/3e12d14dcc70cc9f.
Report an issue: GitHub.