{"record":{"id":"0c4a4ab6c65e2cb4","repo":"cloudflare/cloudflared","slug":"unable-to-unmarshal-logeventtype","errorCode":null,"errorMessage":"unable to unmarshal LogEventType","messagePattern":"unable to unmarshal LogEventType","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"management/events.go","lineNumber":127,"sourceCode":"\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\n)\n\nfunc ParseLogLevel(l string) (LogLevel, bool) {\n\tswitch l {\n\tcase \"debug\":\n\t\treturn Debug, true","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/management/events.go#L109-L145","documentation":"UnmarshalJSON for LogEventType returns this when the JSON value is a string but does not match any known event type per ParseLogEventType. The string parsed fine but is not a recognized LogEventType constant.","triggerScenarios":"ParseLogEventType(s) returns ok=false for a string like 'metrics' (correct is 'cloudflared.metric'), indicating an unknown or misspelled event type string in the JSON payload.","commonSituations":"Clients built against an older/newer management API version using event names that changed; hand-written test payloads with typos.","solutions":["Use an exact supported event type string, e.g. 'cloudflared.metric', 'cloudflared.log'","Upgrade/downgrade the client so its event names match the server's supported set","Check the ParseLogEventType switch in management/events.go for the accepted values"],"exampleFix":"// before\n{\"event_type\": \"metrics\"}\n// after\n{\"event_type\": \"cloudflared.metric\"}","handlingStrategy":"type-guard","validationCode":"if _, ok := management.ParseLogEventType(s); !ok { /* unknown event type, skip */ }","typeGuard":"func isKnownEventType(s string) bool { _, ok := management.ParseLogEventType(s); return ok }","tryCatchPattern":"var e management.LogEventType\nif err := json.Unmarshal(data, &e); err != nil { log.Warn().Err(err).Str(\"event\", s).Msg(\"unknown LogEventType\") }","preventionTips":["Use the exact event type constants, not ad-hoc strings","Regenerate client types when the management API changes","Add a unit test unmarshaling every supported event name"],"tags":["json","unmarshal","management","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}