owasp-amass/amass · error
failed to cast the msg value
Error message
failed to cast the msg value
What it means
JSONLogToRecord found the msg (slog.MessageKey) entry in the JSON log record but its value is not a string (e.g. a number, object, or null), so the type assertion val.(string) fails. This is a type-shape mismatch in the input JSON, not a missing key; the zero slog.Record is returned with this error.
Source
Thrown at internal/afmt/slog.go:49
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) {
case bool:
attrs = append(attrs, slog.Bool(k, val))View on GitHub (pinned to 79299dce87)
Solutions
- Inspect the 'msg' field of the failing JSON record and coerce non-string values to strings before conversion
- Fix the producer so it always writes the log message as a JSON string
- If ingesting third-party JSON, normalize records (json.RawMessage decode then string conversion) before calling JSONLogToRecord
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at internal/afmt/slog.go:49 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/509fca885c8ae067.
Report an issue: GitHub.