{"record":{"id":"6861988b8998e5a1","repo":"uber-go/zap","slug":"unrecognized-level-q-686198","errorCode":null,"errorMessage":"unrecognized level: %q","messagePattern":"unrecognized level: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"zapcore/level.go","lineNumber":175,"sourceCode":"\n// MarshalText marshals the Level to text. Note that the text representation\n// drops the -Level suffix (see example).\nfunc (l Level) MarshalText() ([]byte, error) {\n\treturn []byte(l.String()), nil\n}\n\n// UnmarshalText unmarshals text to a level. Like MarshalText, UnmarshalText\n// expects the text representation of a Level to drop the -Level suffix (see\n// example).\n//\n// In particular, this makes it easy to configure logging levels using YAML,\n// TOML, or JSON files.\nfunc (l *Level) UnmarshalText(text []byte) error {\n\tif l == nil {\n\t\treturn errUnmarshalNilLevel\n\t}\n\tif !l.unmarshalText(text) && !l.unmarshalText(bytes.ToLower(text)) {\n\t\treturn fmt.Errorf(\"unrecognized level: %q\", text)\n\t}\n\treturn nil\n}\n\nfunc (l *Level) unmarshalText(text []byte) bool {\n\tswitch string(text) {\n\tcase \"debug\":\n\t\t*l = DebugLevel\n\tcase \"info\", \"\": // make the zero value useful\n\t\t*l = InfoLevel\n\tcase \"warn\", \"warning\":\n\t\t*l = WarnLevel\n\tcase \"error\":\n\t\t*l = ErrorLevel\n\tcase \"dpanic\":\n\t\t*l = DPanicLevel\n\tcase \"panic\":\n\t\t*l = PanicLevel","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/uber-go/zap/blob/bbd4ecbd8760678fdbac94c93d9aca8069c83b2f/zapcore/level.go#L157-L193","documentation":"Level.UnmarshalText parses textual level names (\"debug\", \"info\", \"warn\", \"error\", \"dpanic\", \"panic\", \"fatal\", case-insensitively). If the text (and its lowercase form) matches none of them, it returns \"unrecognized level: %q\". The nil-receiver case is reported separately as errUnmarshalNilLevel.","triggerScenarios":"Unmarshaling a config value (YAML/JSON/TOML) or calling zapcore.ParseLevel/Set with a string that is not a valid level name, e.g. ParseLevel(\"verbose\"), \"WARNING\" typo variants like \"warnning\", or empty string.","commonSituations":"Config files with misspelled or nonstandard level names (\"trace\", \"verbose\", \"WARN \"+trailing whitespace), environment-variable-driven levels where users supply arbitrary strings, older zap versions lacking \"notice\"/custom levels.","solutions":["Use one of the exact level names: debug, info, warn, error, dpanic, panic, fatal (case-insensitive).","Trim and validate the level string before parsing, e.g. strings.TrimSpace(strings.ToLower(os.Getenv(\"LOG_LEVEL\"))).","Prefer zapcore.ParseLevel with a fallback: on error, log a warning and default to info.","If you need a custom name like \"trace\", map it in your config layer to a real zap level."],"exampleFix":"// before\nlevel, _ := zapcore.ParseLevel(cfg.Level) // \"verbose\" -> unrecognized level\n// after\nlevel, err := zapcore.ParseLevel(cfg.Level)\nif err != nil {\n    level = zapcore.InfoLevel\n}","handlingStrategy":"validation","validationCode":"var validLevels = map[string]bool{\n    \"debug\": true, \"info\": true, \"warn\": true,\n    \"error\": true, \"dpanic\": true, \"panic\": true, \"fatal\": true,\n}\nlvl := strings.TrimSpace(strings.ToLower(os.Getenv(\"LOG_LEVEL\")))\nif !validLevels[lvl] {\n    lvl = \"info\"\n}\nlevel, err := zapcore.ParseLevel(lvl)","typeGuard":null,"tryCatchPattern":"level, err := zapcore.ParseLevel(raw)\nif err != nil {\n    log.Printf(\"invalid LOG_LEVEL %q, defaulting to info\", raw)\n    level = zapcore.InfoLevel\n}","preventionTips":["Validate level strings from config/env against the allowed set before parsing.","Always handle the error from ParseLevel/UnmarshalText — never discard it.","Document the exact accepted level names in your configuration reference."],"tags":["level","parsing","configuration"],"backgroundTag":"unrecognized-log-level","analyzedSha":"bbd4ecbd8760678fdbac94c93d9aca8069c83b2f","analyzedAt":"2026-08-31T13:01:40.228Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}