{"record":{"id":"4cff3a1132531552","repo":"cloudflare/cloudflared","slug":"unable-to-unmarshal-logeventtype-string","errorCode":null,"errorMessage":"unable to unmarshal LogEventType string","messagePattern":"unable to unmarshal LogEventType string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"management/events.go","lineNumber":121,"sourceCode":"\tcase HTTP:\n\t\treturn \"http\"\n\tcase TCP:\n\t\treturn \"tcp\"\n\tcase UDP:\n\t\treturn \"udp\"\n\tdefault:\n\t\treturn \"\"\n\t}\n}\n\nfunc (l LogEventType) MarshalJSON() ([]byte, error) {\n\treturn json.Marshal(l.String())\n}\n\nfunc (e *LogEventType) 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 LogEventType string\")\n\t}\n\tif event, ok := ParseLogEventType(s); ok {\n\t\t*e = event\n\t\treturn nil\n\t}\n\treturn errors.New(\"unable to unmarshal LogEventType\")\n}\n\n// LogLevel corresponds to the zerolog logging levels\n// \"panic\", \"fatal\", and \"trace\" are exempt from this list as they are rarely used and, at least\n// the first two are limited to failure conditions that lead to cloudflared shutting down.\ntype LogLevel int8\n\nconst (\n\tDebug LogLevel = 0\n\tInfo  LogLevel = 1\n\tWarn  LogLevel = 2\n\tError LogLevel = 3","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/management/events.go#L103-L139","documentation":"Thrown by LogEventType.UnmarshalJSON in the management-tunnel protocol when the incoming JSON value for an event-type field is not a JSON string at all (e.g. a number, bool, or array), so json.Unmarshal into a string fails before ParseLogEventType can run. Indicates a malformed or hostile message from the websocket peer.","triggerScenarios":"json.Unmarshal inside LogEventType.UnmarshalJSON fails because the JSON payload contains a non-string value where a LogEventType string (e.g. \"cloudflared.metric\") was expected.","commonSituations":"A management-tier client or test sends a malformed or wrongly-typed event field over the management websocket/HTTP stream.","solutions":["Send the event type as a JSON string, e.g. {\"event_type\": \"cloudflared.metric\"}","Check the event type against the supported ParseLogEventType values","Inspect the raw JSON payload for a numeric or nested value in the event field"],"exampleFix":"// before\n{\"event_type\": 3}\n// after\n{\"event_type\": \"cloudflared.metric\"}","handlingStrategy":"type-guard","validationCode":"if v, ok := raw.(string); ok { _, known := management.ParseLogEventType(v); _ = known }","typeGuard":"func isStringPayload(b []byte) bool { return len(b) > 0 && b[0] == '\"' }","tryCatchPattern":"var e management.LogEventType\nif err := json.Unmarshal(data, &e); err != nil { log.Warn().Err(err).Str(\"payload\", string(data)).Msg(\"bad event type payload\") }","preventionTips":["Always serialize event types as JSON strings","Keep client event-name constants in sync with the management API version"],"tags":["json","unmarshal","management","events"],"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"}