cloudflare/cloudflared · error

unable to unmarshal LogEventType

Error message

unable to unmarshal LogEventType

What it means

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.

Source

Thrown at management/events.go:127

	default:
		return ""
	}
}

func (l LogEventType) MarshalJSON() ([]byte, error) {
	return json.Marshal(l.String())
}

func (e *LogEventType) UnmarshalJSON(data []byte) error {
	var s string
	if err := json.Unmarshal(data, &s); err != nil {
		return errors.New("unable to unmarshal LogEventType string")
	}
	if event, ok := ParseLogEventType(s); ok {
		*e = event
		return nil
	}
	return errors.New("unable to unmarshal LogEventType")
}

// LogLevel corresponds to the zerolog logging levels
// "panic", "fatal", and "trace" are exempt from this list as they are rarely used and, at least
// the first two are limited to failure conditions that lead to cloudflared shutting down.
type LogLevel int8

const (
	Debug LogLevel = 0
	Info  LogLevel = 1
	Warn  LogLevel = 2
	Error LogLevel = 3
)

func ParseLogLevel(l string) (LogLevel, bool) {
	switch l {
	case "debug":
		return Debug, true

View on GitHub (pinned to 2253eeeb25)

Solutions

  1. Use an exact supported event type string, e.g. 'cloudflared.metric', 'cloudflared.log'
  2. Upgrade/downgrade the client so its event names match the server's supported set
  3. Check the ParseLogEventType switch in management/events.go for the accepted values

Example fix

// before
{"event_type": "metrics"}
// after
{"event_type": "cloudflared.metric"}
Defensive patterns

Strategy: type-guard

Validate before calling

if _, ok := management.ParseLogEventType(s); !ok { /* unknown event type, skip */ }

Type guard

func isKnownEventType(s string) bool { _, ok := management.ParseLogEventType(s); return ok }

Try / catch

var e management.LogEventType
if err := json.Unmarshal(data, &e); err != nil { log.Warn().Err(err).Str("event", s).Msg("unknown LogEventType") }

Prevention

When it happens

Trigger: 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.

Common situations: Clients built against an older/newer management API version using event names that changed; hand-written test payloads with typos.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06). Data as JSON: /api/errors/0c4a4ab6c65e2cb4. Report an issue: GitHub.