{"record":{"id":"18db0aaee7386038","repo":"cloudflare/cloudflared","slug":"unable-to-unmarshal-loglevel-string","errorCode":null,"errorMessage":"unable to unmarshal LogLevel string","messagePattern":"unable to unmarshal LogLevel string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"management/events.go","lineNumber":178,"sourceCode":"\tcase Info:\n\t\treturn \"info\"\n\tcase Warn:\n\t\treturn \"warn\"\n\tcase Error:\n\t\treturn \"error\"\n\tdefault:\n\t\treturn \"\"\n\t}\n}\n\nfunc (l LogLevel) MarshalJSON() ([]byte, error) {\n\treturn json.Marshal(l.String())\n}\n\nfunc (l *LogLevel) UnmarshalJSON(data []byte) error {\n\tvar s string\n\tif err := json.Unmarshal(data, &s); err != nil {\n\t\treturn errors.New(\"unable to unmarshal LogLevel string\")\n\t}\n\tif level, ok := ParseLogLevel(s); ok {\n\t\t*l = level\n\t\treturn nil\n\t}\n\treturn fmt.Errorf(\"unable to unmarshal LogLevel\")\n}\n\nconst (\n\t// TimeKey aligns with the zerolog.TimeFieldName\n\tTimeKey = \"time\"\n\t// LevelKey aligns with the zerolog.LevelFieldName\n\tLevelKey = \"level\"\n\t// LevelKey aligns with the zerolog.MessageFieldName\n\tMessageKey = \"message\"\n\t// EventTypeKey is the custom JSON key of the LogEventType in ZeroLogEvent\n\tEventTypeKey = \"event\"\n\t// FieldsKey is a custom JSON key to match and store every other key for a zerolog event","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/management/events.go#L160-L196","documentation":"Thrown by LogLevel.UnmarshalJSON when the incoming JSON value for a log-level field is not a JSON string (e.g. number or object), so unmarshalling into a string fails. This is the malformed-payload case, distinct from the later 'unable to unmarshal LogLevel' case where the string is well-formed but not a recognized level.","triggerScenarios":"json.Unmarshal inside LogLevel.UnmarshalJSON fails because the payload contains a non-string (number, bool, object) in a field expected to be a LogLevel string.","commonSituations":"A management-stream client sending a numeric log level or a malformed JSON message over the session.","solutions":["Send the log level as a JSON string, e.g. {\"level\": \"debug\"}","Only use levels supported by ParseLogLevel (debug, info, warn, error, etc.)","Inspect the raw payload for a wrongly-typed level field"],"exampleFix":"// before\n{\"level\": 2}\n// after\n{\"level\": \"debug\"}","handlingStrategy":"type-guard","validationCode":"if _, ok := management.ParseLogLevel(s); !ok { /* unsupported level */ }","typeGuard":"func isKnownLogLevel(s string) bool { _, ok := management.ParseLogLevel(s); return ok }","tryCatchPattern":"var l management.LogLevel\nif err := json.Unmarshal(data, &l); err != nil { log.Warn().Err(err).Msg(\"bad LogLevel payload\") }","preventionTips":["Send log levels as lowercase strings (\"debug\",\"info\",\"warn\",\"error\")","Never send numeric levels over the management stream"],"tags":["json","unmarshal","management","loglevel"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}