owasp-amass/amass · error

failed to find the msg key

Error message

failed to find the msg key

What it means

JSONLogToRecord could not find the msg (slog.MessageKey) entry in a JSON log record it was converting back into a slog.Record. The input JSON map simply lacks the 'msg' field, so the record cannot be rebuilt; the zero slog.Record is returned along with this error. Called from WriteLogMessage when replaying/parsing JSON log output.

Source

Thrown at internal/afmt/slog.go:47

		}
	}
	delete(j, slog.TimeKey)

	var level slog.Level
	// extract the log level for the new record
	if val, found := j[slog.LevelKey]; !found {
		return slog.Record{}, errors.New("failed to find the level key")
	} else if str, ok := val.(string); !ok {
		return slog.Record{}, errors.New("failed to cast the level value")
	} else if level.UnmarshalText([]byte(str)) != nil {
		return slog.Record{}, errors.New("failed to unmarshal the level text")
	}
	delete(j, slog.LevelKey)

	var msg string
	// extract the log message for the new record
	if val, found := j[slog.MessageKey]; !found {
		return slog.Record{}, errors.New("failed to find the msg key")
	} else if str, ok := val.(string); !ok {
		return slog.Record{}, errors.New("failed to cast the msg value")
	} else {
		msg = str
	}
	delete(j, slog.MessageKey)

	var pc uintptr
	record := slog.NewRecord(ltime, level, msg, pc)
	record.AddAttrs(jsonToAttrs(j)...)
	return record, nil
}

func jsonToAttrs(jmap map[string]any) []slog.Attr {
	var attrs []slog.Attr

	for k, v := range jmap {
		switch val := v.(type) {

View on GitHub (pinned to 79299dce87)

Solutions

  1. Check the JSON being fed to WriteLogMessage/JSONLogToRecord and confirm each object contains a non-empty "msg" key
  2. If the producer is a slog JSONHandler, verify records were serialized with the default keys (time, level, msg) and not renamed via HandlerOptions
  3. Log or dump the offending JSON object to identify which producer emitted records without 'msg'
  4. Skip or quarantine malformed lines instead of failing the whole conversion loop if best-effort ingestion is acceptable
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/afmt/slog.go:47 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of owasp-amass/amass@79299dce87 (2026-09-06). Data as JSON: /api/errors/14aa32aea65b7593. Report an issue: GitHub.