crowdsecurity/crowdsec · error

target is not a map[string]string

Error message

target is not a map[string]string

What it means

Type guard in ParseKV: the target map already contains an entry under the given prefix, but that existing value is not a map[string]string — a previous stage stored an incompatible type under the same prefix key.

Source

Thrown at pkg/exprhelpers/helpers.go:997

func ParseKV(params ...any) (any, error) {
	blob := params[0].(string)
	target := params[1].(map[string]any)
	prefix := params[2].(string)

	matches := keyValuePattern.FindAllStringSubmatch(blob, -1)
	if matches == nil {
		log.Errorf("could not find any key/value pair in line")
		return nil, errors.New("invalid input format")
	}

	if _, ok := target[prefix]; !ok {
		target[prefix] = make(map[string]string)
	} else {
		_, ok := target[prefix].(map[string]string)
		if !ok {
			log.Errorf("ParseKV: target is not a map[string]string")
			return nil, errors.New("target is not a map[string]string")
		}
	}

	for _, match := range matches {
		key := ""
		value := ""

		for i, name := range keyValuePattern.SubexpNames() {
			switch {
			case name == "key":
				key = match[i]
			case name == "quoted_value" && match[i] != "":
				value = match[i]
			case name == "value" && match[i] != "":
				value = match[i]
			}
		}

View on GitHub (pinned to 909b515798)

Solutions

  1. Use a fresh/unique prefix for each ParseKV call so target entries don't collide
  2. Ensure earlier stages don't write non-KV data under the same prefix key
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at pkg/exprhelpers/helpers.go:997 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/4e1b0a012a6b9c8c. Report an issue: GitHub.