amir20/dozzle · info

invalid format: key is empty

Error message

invalid format: key is empty

What it means

ParseLogFmt in internal/container/logfmt.go parses logfmt-style lines (key=value pairs). It raises 'invalid format: key is empty' when it encounters '=' while isKey is true with start >= i, i.e. there is no non-empty key before the '=' sign. It returns nil along with the error, aborting parsing of that line.

Solutions

  1. Fix the producing application so every key=value pair has a non-empty key
  2. Strip or quote message text starting with '=' so it isn't parsed as a logfmt key
  3. Treat parse failure as fallback: log the line as a plain SimpleLogEntry instead of structured fields
  4. If you control parsing, skip empty keys and continue parsing the remainder of the line rather than failing

Example fix

// before
if start >= i {
    return nil, errors.New("invalid format: key is empty")
}
// after: skip malformed segment, keep parsing
if start >= i {
    isKey = false
    start = i + 1
    continue
}
Defensive patterns

Strategy: fallback

Validate before calling

if (/^\s*=/.test(line) || /(^|\s)=/.test(line)) {
  // not valid logfmt; render as plain text instead of calling ParseLogFmt
}

Type guard

func looksLikeLogFmt(line string) bool {
    return strings.Contains(line, "=") && !strings.HasPrefix(strings.TrimSpace(line), "=")
}

Try / catch

fields, err := ParseLogFmt(line)
if err != nil {
    event.Message = line // fall back to plain-text log entry
} else {
    event.Fields = fields
}

Prevention

When it happens

Trigger: A log line containing '=value', ' =value', or a leading '=value' segment, or two consecutive spaces before '=' collapse into an empty key (start == i at the '=').

Common situations: Application logs emit lines like '=foo' or a message beginning with '=' (e.g. '== Marker =='), or logfmt detection misfires on non-logfmt text; hand-rolled log lines with missing keys ('=error level=3').

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

Thrown at internal/container/logfmt.go:23

	"strconv"
	"strings"

	orderedmap "github.com/wk8/go-ordered-map/v2"
)

// ParseLogFmt parses a log entry in logfmt format and returns a map of key-value pairs.
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])

View on GitHub (pinned to d9463cbe21)