{"record":{"id":"e22521a79c99c9f8","repo":"go-kratos/kratos","slug":"cannot-register-a-nil-codec","errorCode":null,"errorMessage":"cannot register a nil Codec","messagePattern":"cannot register a nil Codec","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"encoding/encoding.go","lineNumber":27,"sourceCode":"// methods can be called from concurrent goroutines.\ntype Codec interface {\n\t// Marshal returns the wire format of v.\n\tMarshal(v any) ([]byte, error)\n\t// Unmarshal parses the wire format into v.\n\tUnmarshal(data []byte, v any) error\n\t// Name returns the name of the Codec implementation. The returned string\n\t// will be used as part of content type in transmission. The result must be\n\t// static; the result cannot change between calls.\n\tName() string\n}\n\nvar registeredCodecs = make(map[string]Codec)\n\n// RegisterCodec registers the provided Codec for use with all Transport clients and\n// servers.\nfunc RegisterCodec(codec Codec) {\n\tif codec == nil {\n\t\tpanic(\"cannot register a nil Codec\")\n\t}\n\tif codec.Name() == \"\" {\n\t\tpanic(\"cannot register Codec with empty string result for Name()\")\n\t}\n\tcontentSubtype := strings.ToLower(codec.Name())\n\tregisteredCodecs[contentSubtype] = codec\n}\n\n// GetCodec gets a registered Codec by content-subtype, or nil if no Codec is\n// registered for the content-subtype.\n//\n// The content-subtype is expected to be lowercase.\nfunc GetCodec(contentSubtype string) Codec {\n\treturn registeredCodecs[contentSubtype]\n}\n","sourceCodeStart":9,"sourceCodeEnd":43,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/encoding/encoding.go#L9-L43","documentation":"Error \"cannot register a nil Codec\" thrown in go-kratos/kratos.","triggerScenarios":"Thrown at encoding/encoding.go:27 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}