amir20/dozzle · error

invalid format: unexpected space in key

Error message

invalid format: unexpected space in key

What it means

ParseLogFmt rejects a logfmt line where a key being scanned contains a space followed by more characters before '=' (e.g. 'foo bar=1'). The parser only allows spaces between pairs, so a space inside a key position means the line is not valid logfmt and parsing aborts for the whole line.

Solutions

  1. Fix the emitting application so keys contain no spaces (logfmt keys must be bare tokens).
  2. Quote the key's value properly instead, e.g. change 'foo bar=1' to 'foo=bar key=value'.
  3. Pre-sanitize or drop non-conforming log lines before calling ParseLogFmt if upstream logs are untrusted.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/container/logfmt.go:30 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of amir20/dozzle@d9463cbe21 (2026-09-07). Data as JSON: /api/errors/abba2d249b24a55d. Report an issue: GitHub.

Appendix: source

Thrown at internal/container/logfmt.go:30

func ParseLogFmt(log string) (*orderedmap.OrderedMap[string, string], error) {
	result := orderedmap.New[string, string]()
	var key, value string
	inQuotes, escaping, isKey := false, false, true
	start := 0

	for i := 0; i < len(log); i++ {
		char := log[i]
		if isKey {
			if char == '=' {
				if start >= i {
					return nil, errors.New("invalid format: key is empty")
				}
				key = log[start:i]
				isKey = false
				start = i + 1
			} else if char == ' ' {
				if i > start {
					return nil, errors.New("invalid format: unexpected space in key")
				}
			}

		} else {
			if inQuotes {
				if escaping {
					escaping = false
				} else if char == '\\' {
					escaping = true
				} else if char == '"' {
					value = unescapeQuoted(log[start-1 : i+1])
					result.Set(key, value)
					inQuotes = false
					isKey = true
					start = i + 2
				}
			} else {
				if char == '"' {

View on GitHub (pinned to d9463cbe21)