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 (testing variant) checks the initial bytes from the wrapped reader against sr.signature and, if they differ, replaces the read error with this formatted mismatch error containing hex dumps of got and want. It fires when a stream expected to start with a specific magic-number prefix (e.g. an image header) starts with something else; after the check the signature is cleared so subsequent reads pass through.

Source

Thrown at interfaces/18-testing/reader.go:36

// 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 {
		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
	return
}

View on GitHub (pinned to 3c475a78e5)

Solutions

  1. Inspect the got/want dumps to see what the actual content is and correct the expected signature.
  2. Abort reading and report the unexpected content type to the user or test.
  3. Verify the URL/resource actually serves the expected file format before streaming.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at interfaces/18-testing/reader.go:36 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/055edd0dbf6fbeae. Report an issue: GitHub.