thanos-io/thanos · error

alertState: unquote

Error message

alertState: unquote %v

What it means

Raised in AlertState.UnmarshalJSON, a custom JSON unmarshaller for the alert state enum. It fires when the JSON value for a rule's state is not a quoted string (e.g., a number, object, or malformed JSON), so strconv.Unquote fails; the offending raw bytes are included in the error.

Solutions

  1. Ensure the alertState field is a JSON string (e.g., "firing", "inactive", "pending")
  2. Check the JSON producer for numeric/enum serialization instead of string
  3. Validate the payload structure before unmarshaling
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/rules/rulespb/custom.go:275 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/6d9e79f7f7a4021a. Report an issue: GitHub.

Appendix: source

Thrown at pkg/rules/rulespb/custom.go:275

	}{
		Alert: a,
		Type:  RuleAlertingType,
	})
}

func (r *RuleGroup) MarshalJSON() ([]byte, error) {
	if r.Rules == nil {
		// Ensure that empty slices are marshaled as '[]' and not 'null'.
		r.Rules = make([]*Rule, 0)
	}
	type plain RuleGroup
	return json.Marshal((*plain)(r))
}

func (x *AlertState) UnmarshalJSON(entry []byte) error {
	fieldStr, err := strconv.Unquote(string(entry))
	if err != nil {
		return errors.Wrapf(err, "alertState: unquote %v", string(entry))
	}

	if fieldStr == "" {
		return errors.New("empty alertState")
	}

	state, ok := AlertState_value[strings.ToUpper(fieldStr)]
	if !ok {
		return errors.Errorf("unknown alertState: %v", string(entry))
	}
	*x = AlertState(state)
	return nil
}

func (x *AlertState) MarshalJSON() ([]byte, error) {
	return []byte(strconv.Quote(strings.ToLower(x.String()))), nil
}

View on GitHub (pinned to 35b8b99117)