{"record":{"id":"3e12d14dcc70cc9f","repo":"inancgumus/learngo","slug":"signature-doesn-t-match-got-x-want-x","errorCode":null,"errorMessage":"signature doesn't match, got: % x, want: % x","messagePattern":"signature doesn't match, got: % x, want: % x","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"interfaces/17-write-an-io-reader/reader.go","lineNumber":41,"sourceCode":"// Read implements the io.Reader interface.\nfunc (sr *signatureReader) Read(b []byte) (n int, err error) {\n\tn, err = sr.r.Read(b)\n\n\tl := len(sr.signature)\n\tif l == 0 {\n\t\t// simply return if the signature has already been detected.\n\t\treturn\n\t}\n\tif lb := len(b); lb < l {\n\t\tl = lb\n\t}\n\tif got, want := b[:l], sr.signature[:l]; !bytes.Equal(got, want) {\n\t\terr = fmt.Errorf(\"signature doesn't match, got: % x, want: % x\", got, want)\n\t}\n\tsr.signature = nil // or similar clearing in the full source\n\treturn\n}","sourceCodeStart":23,"sourceCodeEnd":57,"githubUrl":"https://github.com/inancgumus/learngo/blob/3c475a78e54336c6255e925ff66b8ef4da6a2ae7/interfaces/17-write-an-io-reader/reader.go#L23-L57","documentation":"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.","triggerScenarios":"Thrown at interfaces/17-write-an-io-reader/reader.go:41 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3c475a78e54336c6255e925ff66b8ef4da6a2ae7","analyzedAt":"2026-09-02T10:14:38.492Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}