{"record":{"id":"7a4c23acdf8831a4","repo":"t8y2/dbx","slug":"reader-cannot-read-token-payload-7a4c23","errorCode":null,"errorMessage":"reader cannot read token payload","messagePattern":"reader cannot read token payload","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/hive-go/config.go","lineNumber":815,"sourceCode":"\t}\n\treturn identifier, password, nil\n}\n\nfunc readHadoopByteArray(reader io.ByteReader) ([]byte, error) {\n\tlength, err := readHadoopVInt(reader)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif length < 0 {\n\t\treturn nil, fmt.Errorf(\"negative length %d\", length)\n\t}\n\tif length > 64*1024*1024 {\n\t\treturn nil, fmt.Errorf(\"length %d exceeds limit\", length)\n\t}\n\tvalue := make([]byte, int(length))\n\tbyteReader, ok := reader.(io.Reader)\n\tif !ok {\n\t\treturn nil, errors.New(\"reader cannot read token payload\")\n\t}\n\tif _, err := io.ReadFull(byteReader, value); err != nil {\n\t\treturn nil, err\n\t}\n\treturn value, nil\n}\n\nfunc readHadoopVInt(reader io.ByteReader) (int64, error) {\n\tfirstByte, err := reader.ReadByte()\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tfirst := int8(firstByte)\n\tif first >= -112 {\n\t\treturn int64(first), nil\n\t}\n\tlength := -111 - int(first)\n\tnegative := false","sourceCodeStart":797,"sourceCodeEnd":833,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/hive-go/config.go#L797-L833","documentation":"This error is returned when a token-callback payload reader does not implement io.Reader, so the driver cannot pull the raw token bytes out of it. The validation function copies up to the stated length from the supplied reader via io.ReadFull, but a non-io.Reader value cannot be drained. It is a programming/interface-contract error rather than a runtime I/O failure.","triggerScenarios":"Calling the token payload reader function with a value that is not an io.Reader (e.g. a struct, a string, or a custom type without a Read method), typically when wiring a custom token provider callback into the Hive agent config.","commonSituations":"Passing a custom token cache object that exposes its own Read-like method but does not implement the io.Reader interface; wrapping a reader in a type the author assumed was compatible; refactoring code that previously passed an *bytes.Reader.","solutions":["Wrap the payload in an io.Reader before passing it (bytes.NewReader(payload)).","Implement Read(p []byte) (int, error) on the custom type so it satisfies io.Reader.","Use a plain *bytes.Buffer or *strings.Reader for in-memory payloads."],"exampleFix":"// before\nagent.SetTokenReader(myTokenHolder) // myTokenHolder is not io.Reader\n// after\nagent.SetTokenReader(bytes.NewReader(myTokenHolder.Payload()))","handlingStrategy":"validation","validationCode":"func isReader(v any) bool {\n\t_, ok := v.(io.Reader)\n\treturn ok\n}\nif !isReader(tokenProvider) {\n\treturn fmt.Errorf(\"token provider %T does not implement io.Reader\", tokenProvider)\n}","typeGuard":"func asReader(v any) (io.Reader, bool) {\n\tr, ok := v.(io.Reader)\n\treturn r, ok\n}","tryCatchPattern":null,"preventionTips":["Always pass *bytes.Reader, *bytes.Buffer, or *strings.Reader for in-memory token payloads","Add a compile-time assertion: var _ io.Reader = (*MyTokenType)(nil)","Run `go vet` and interface satisfaction checks in CI"],"tags":["go","io","interface-mismatch","config"],"backgroundTag":"reader-does-not-implement-io-reader","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}