{"record":{"id":"40f136bc447f6712","repo":"uber-go/zap","slug":"no-encoder-name-specified","errorCode":null,"errorMessage":"no encoder name specified","messagePattern":"no encoder name specified","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"encoder.go","lineNumber":32,"sourceCode":"// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n\npackage zap\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"sync\"\n\n\t\"go.uber.org/zap/zapcore\"\n)\n\nvar (\n\terrNoEncoderNameSpecified = errors.New(\"no encoder name specified\")\n\n\t_encoderNameToConstructor = map[string]func(zapcore.EncoderConfig) (zapcore.Encoder, error){\n\t\t\"console\": func(encoderConfig zapcore.EncoderConfig) (zapcore.Encoder, error) {\n\t\t\treturn zapcore.NewConsoleEncoder(encoderConfig), nil\n\t\t},\n\t\t\"json\": func(encoderConfig zapcore.EncoderConfig) (zapcore.Encoder, error) {\n\t\t\treturn zapcore.NewJSONEncoder(encoderConfig), nil\n\t\t},\n\t}\n\t_encoderMutex sync.RWMutex\n)\n\n// RegisterEncoder registers an encoder constructor, which the Config struct\n// can then reference. By default, the \"json\" and \"console\" encoders are\n// registered.\n//\n// Attempting to register an encoder whose name is already taken returns an\n// error.","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/uber-go/zap/blob/bbd4ecbd8760678fdbac94c93d9aca8069c83b2f/encoder.go#L14-L50","documentation":"RegisterEncoder (e.g. LowercaseColorLevelEncoder / CapitalColorLevelEncoder wrappers) requires a non-empty name under which the encoder constructor is stored. Passing an empty name returns the sentinel errNoEncoderNameSpecified because there would be no way to look the encoder up later.","triggerScenarios":"Calling zap.RegisterEncoder(\"\", constructor) or the color-level encoder registration helpers with an empty encoder name string.","commonSituations":"Programmatic registration where the name comes from a variable/config value that is empty; test code building encoders dynamically without validating the name first.","solutions":["Pass a non-empty name string to RegisterEncoder, e.g. zap.RegisterEncoder(\"myjson\", func(cfg zapcore.EncoderConfig) (zapcore.Encoder, error){...})","Validate/guard the encoder name variable before registering"],"exampleFix":"// before\nerr := zap.RegisterEncoder(name, ctor) // name == \"\"\n// after\nif name == \"\" { return errors.New(\"encoder name required\") }\nerr := zap.RegisterEncoder(name, ctor)","handlingStrategy":"validation","validationCode":"if name == \"\" {\n    return fmt.Errorf(\"encoder name required\")\n}\nerr := zap.RegisterEncoder(name, ctor)","typeGuard":null,"tryCatchPattern":"if err := zap.RegisterEncoder(name, ctor); err != nil {\n    return fmt.Errorf(\"register encoder: %w\", err)\n}","preventionTips":["Validate encoder name strings before registration","Never hardcode empty names; source names from constants"],"tags":["encoder","registration","zap","go"],"backgroundTag":"empty-required-argument","analyzedSha":"bbd4ecbd8760678fdbac94c93d9aca8069c83b2f","analyzedAt":"2026-08-31T13:01:40.228Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}