{"record":{"id":"94eb0468b2abcd06","repo":"thanos-io/thanos","slug":"empty-alertstate","errorCode":null,"errorMessage":"empty alertState","messagePattern":"empty alertState","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/rules/rulespb/custom.go","lineNumber":279,"sourceCode":"}\n\nfunc (r *RuleGroup) MarshalJSON() ([]byte, error) {\n\tif r.Rules == nil {\n\t\t// Ensure that empty slices are marshaled as '[]' and not 'null'.\n\t\tr.Rules = make([]*Rule, 0)\n\t}\n\ttype plain RuleGroup\n\treturn json.Marshal((*plain)(r))\n}\n\nfunc (x *AlertState) UnmarshalJSON(entry []byte) error {\n\tfieldStr, err := strconv.Unquote(string(entry))\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"alertState: unquote %v\", string(entry))\n\t}\n\n\tif fieldStr == \"\" {\n\t\treturn errors.New(\"empty alertState\")\n\t}\n\n\tstate, ok := AlertState_value[strings.ToUpper(fieldStr)]\n\tif !ok {\n\t\treturn errors.Errorf(\"unknown alertState: %v\", string(entry))\n\t}\n\t*x = AlertState(state)\n\treturn nil\n}\n\nfunc (x *AlertState) MarshalJSON() ([]byte, error) {\n\treturn []byte(strconv.Quote(strings.ToLower(x.String()))), nil\n}\n\n// Compare compares alert state x and y and returns:\n//\n//\t< 0 if x < y  (alert state x is more critical than alert state y)\n//\t  0 if x == y","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/rules/rulespb/custom.go#L261-L297","documentation":"Raised in AlertState.UnmarshalJSON as a guard: the unquoted alert-state string is empty, meaning the JSON payload contained \"\" (or an escaped empty string) for the rule state, which maps to no valid AlertState value.","triggerScenarios":"Thrown at pkg/rules/rulespb/custom.go:279 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide a non-empty state string such as \"firing\", \"pending\", or \"inactive\"","Fix the producer that emits empty state fields","Add client-side validation to reject empty state before decoding"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}