{"record":{"id":"eccb8c8f67bb19f6","repo":"owasp-amass/amass","slug":"failed-to-unmarshal-the-level-text","errorCode":null,"errorMessage":"failed to unmarshal the level text","messagePattern":"failed to unmarshal the level text","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/afmt/slog.go","lineNumber":40,"sourceCode":"\n\tltime := time.Now()\n\tif timeVal, found := j[slog.TimeKey]; found {\n\t\tif timestr, valid := timeVal.(string); valid {\n\t\t\tif t, err := time.Parse(\"2006-01-02T15:04:05.000000000Z\", timestr); err == nil {\n\t\t\t\tltime = t\n\t\t\t}\n\t\t}\n\t}\n\tdelete(j, slog.TimeKey)\n\n\tvar level slog.Level\n\t// extract the log level for the new record\n\tif val, found := j[slog.LevelKey]; !found {\n\t\treturn slog.Record{}, errors.New(\"failed to find the level key\")\n\t} else if str, ok := val.(string); !ok {\n\t\treturn slog.Record{}, errors.New(\"failed to cast the level value\")\n\t} else if level.UnmarshalText([]byte(str)) != nil {\n\t\treturn slog.Record{}, errors.New(\"failed to unmarshal the level text\")\n\t}\n\tdelete(j, slog.LevelKey)\n\n\tvar msg string\n\t// extract the log message for the new record\n\tif val, found := j[slog.MessageKey]; !found {\n\t\treturn slog.Record{}, errors.New(\"failed to find the msg key\")\n\t} else if str, ok := val.(string); !ok {\n\t\treturn slog.Record{}, errors.New(\"failed to cast the msg value\")\n\t} else {\n\t\tmsg = str\n\t}\n\tdelete(j, slog.MessageKey)\n\n\tvar pc uintptr\n\trecord := slog.NewRecord(ltime, level, msg, pc)\n\trecord.AddAttrs(jsonToAttrs(j)...)\n\treturn record, nil","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/internal/afmt/slog.go#L22-L58","documentation":"The level value was a string, but slog.Level.UnmarshalText could not parse it into a valid slog.Level; this error is returned instead of propagating the parse failure detail. Only recognized level names (DEBUG, INFO, WARN, ERROR and their variants) are accepted.","triggerScenarios":"JSONLogToRecord receives a log line with a string \"level\" whose text is not a valid slog level — e.g. \"verbose\", \"TRACE\", \"warning\" (lowercase works for some parsers but arbitrary aliases do not), or an empty string.","commonSituations":"Custom level names from a producer using its own level enum; case/format drift between producer and consumer; an engine version that introduced levels the consumer's slog version does not know.","solutions":["Use standard slog level names (DEBUG, INFO, WARN/WARNING, ERROR) in the producer's JSON output","Map custom producer levels to slog levels before calling JSONLogToRecord","Align producer and consumer library versions so supported level sets match","Check for stray whitespace or casing issues; normalize the level string before parsing"],"exampleFix":"// before\n{\"time\":\"...\",\"level\":\"verbose\",\"msg\":\"started\"}\n// after\n{\"time\":\"...\",\"level\":\"DEBUG\",\"msg\":\"started\"}","handlingStrategy":"validation","validationCode":"var validLevels = map[string]bool{\"DEBUG\":true,\"INFO\":true,\"WARN\":true,\"WARNING\":true,\"ERROR\":true}\nif v, ok := j[slog.LevelKey].(string); ok && !validLevels[v] {\n    return fmt.Errorf(\"unknown log level %q\", v)\n}","typeGuard":null,"tryCatchPattern":"rec, err := afmt.JSONLogToRecord(line)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to unmarshal the level text\") {\n        rawLog.Printf(\"unparseable level in log line: %q\", line)\n        return nil\n    }\n    return err\n}","preventionTips":["Restrict the producer to standard slog level names (DEBUG, INFO, WARN, ERROR)","Normalize alias levels (e.g. TRACE->DEBUG, verbose->DEBUG) before writing","Trim whitespace and normalize casing of the level string at the source","Test level parsing whenever either library version changes"],"tags":["logging","json","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}