{"record":{"id":"6d9e79f7f7a4021a","repo":"thanos-io/thanos","slug":"alertstate-unquote-v","errorCode":null,"errorMessage":"alertState: unquote %v","messagePattern":"alertState: unquote (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/rules/rulespb/custom.go","lineNumber":275,"sourceCode":"\t}{\n\t\tAlert: a,\n\t\tType:  RuleAlertingType,\n\t})\n}\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","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/rules/rulespb/custom.go#L257-L293","documentation":"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.","triggerScenarios":"Thrown at pkg/rules/rulespb/custom.go:275 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the alertState field is a JSON string (e.g., \"firing\", \"inactive\", \"pending\")","Check the JSON producer for numeric/enum serialization instead of string","Validate the payload structure before unmarshaling"],"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"}