hashicorp/nomad · error

Invalid key value pair for topic, topic: %s

Error message

Invalid key value pair for topic, topic: %s

What it means

parseTopic expects each topic string to be either a bare topic name (wildcard '*' value inferred) or exactly key:value with a single colon. Any string with two or more colons — producing 3+ parts after strings.Split — is invalid and rejected with this message.

Source

Thrown at command/agent/event_endpoint.go:235

	for _, topic := range raw {
		k, v, err := parseTopic(topic)
		if err != nil {
			return nil, fmt.Errorf("error parsing topics: %w", err)
		}

		topics[structs.Topic(k)] = append(topics[structs.Topic(k)], v)
	}
	return topics, nil
}

func parseTopic(topic string) (string, string, error) {
	parts := strings.Split(topic, ":")
	// infer wildcard if only given a topic
	if len(parts) == 1 {
		return topic, "*", nil
	} else if len(parts) != 2 {
		return "", "", fmt.Errorf("Invalid key value pair for topic, topic: %s", topic)
	}
	return parts[0], parts[1], nil
}

func allTopics() map[structs.Topic][]string {
	return map[structs.Topic][]string{"*": {"*"}}
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Remove extra colons; the key (topic name) must not contain ':'.
  2. Emit multiple topic= parameters instead of combining into one.
  3. Use the bare topic name without a value to get wildcard matching.
  4. Validate topic strings client-side (one optional colon) before building the request.

Example fix

// before
topic=Deployment:us-west:prod
// after
topic=Deployment:us-west-prod
Defensive patterns

Strategy: validation

Validate before calling

func validateTopicParam(topic string) error {
  parts := strings.Split(topic, ":")
  if len(parts) > 2 {
    return fmt.Errorf("topic %q must have at most one ':'", topic)
  }
  return nil
}

Type guard

func isWellFormedTopic(t string) bool {
  parts := strings.Split(t, ":")
  return len(parts) == 1 || len(parts) == 2
}

Try / catch

k, v, err := parseTopic(topic)
if err != nil {
  return fmt.Errorf("skip malformed topic %q: %w", topic, err)
}

Prevention

When it happens

Trigger: Passing topic values like "Deployment:eval-123:extra" to parseEventTopics (from EventStream query params) — i.e., more than one ':' separator in a single topic query parameter.

Common situations: Appending filter keys that themselves contain colons; joining multiple topic filters into one parameter with colons; copy-pasting an event payload as the topic key.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/60890bb1df0c3033. Report an issue: GitHub.