{"id":"76c942349eeb6275","repo":"go-redis/redis","slug":"redis-can-t-marshal-t-implement-encoding-binary","errorCode":null,"errorMessage":"redis: can't marshal %T (implement encoding.BinaryMarshaler)","messagePattern":"redis: can't marshal %T \\(implement encoding\\.BinaryMarshaler\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/proto/writer.go","lineNumber":197,"sourceCode":"\t\tw.numBuf = v.AppendFormat(w.numBuf[:0], time.RFC3339Nano)\n\t\treturn w.bytes(w.numBuf)\n\tcase time.Duration:\n\t\treturn w.int(v.Nanoseconds())\n\tcase *time.Duration:\n\t\tif v == nil {\n\t\t\treturn w.int(0)\n\t\t}\n\t\treturn w.int(v.Nanoseconds())\n\tcase encoding.BinaryMarshaler:\n\t\tb, err := v.MarshalBinary()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\treturn w.bytes(b)\n\tcase net.IP:\n\t\treturn w.bytes(v)\n\tdefault:\n\t\treturn fmt.Errorf(\n\t\t\t\"redis: can't marshal %T (implement encoding.BinaryMarshaler)\", v)\n\t}\n}\n\nfunc (w *Writer) bytes(b []byte) error {\n\tif err := w.WriteByte(RespString); err != nil {\n\t\treturn err\n\t}\n\n\tif err := w.writeLen(len(b)); err != nil {\n\t\treturn err\n\t}\n\n\tif _, err := w.Write(b); err != nil {\n\t\treturn err\n\t}\n\n\treturn w.crlf()","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/internal/proto/writer.go#L179-L215","documentation":"Error \"redis: can't marshal %T (implement encoding.BinaryMarshaler)\" thrown in go-redis/redis.","triggerScenarios":"Thrown at internal/proto/writer.go:197 when the library encounters an invalid state.","commonSituations":"Marshal custom argument types explicitly at the call site.","solutions":["Implement encoding.BinaryMarshaler on the argument type","Convert the value to string/[]byte/int before passing it as a command argument"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}