{"record":{"id":"c3c4446f92ff332e","repo":"thanos-io/thanos","slug":"unknown-targethealth-v","errorCode":null,"errorMessage":"unknown targetHealth: %v","messagePattern":"unknown targetHealth: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/targets/targetspb/custom.go","lineNumber":44,"sourceCode":"\t\tResult: &TargetsResponse_Warning{\n\t\t\tWarning: warning.Error(),\n\t\t},\n\t}\n}\n\nfunc (x *TargetHealth) UnmarshalJSON(entry []byte) error {\n\tfieldStr, err := strconv.Unquote(string(entry))\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"targetHealth: unquote %v\", string(entry))\n\t}\n\n\tif fieldStr == \"\" {\n\t\treturn errors.New(\"empty targetHealth\")\n\t}\n\n\tstate, ok := TargetHealth_value[strings.ToUpper(fieldStr)]\n\tif !ok {\n\t\treturn errors.Errorf(\"unknown targetHealth: %v\", string(entry))\n\t}\n\t*x = TargetHealth(state)\n\treturn nil\n}\n\nfunc (x *TargetHealth) MarshalJSON() ([]byte, error) {\n\treturn []byte(strconv.Quote(strings.ToLower(x.String()))), nil\n}\n\nfunc (x TargetHealth) Compare(y TargetHealth) int {\n\treturn int(x) - int(y)\n}\n\nfunc (t1 *ActiveTarget) Compare(t2 *ActiveTarget) int {\n\tif d := strings.Compare(t1.ScrapeUrl, t2.ScrapeUrl); d != 0 {\n\t\treturn d\n\t}\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/targets/targetspb/custom.go#L26-L62","documentation":"TargetHealth.UnmarshalJSON looks up the unquoted, upper-cased string in TargetHealth_value (the protobuf-generated enum value map). If the string is not a known state, this error reports the unknown raw JSON entry.","triggerScenarios":"UnmarshalJSON is given a quoted string whose value is not unknown/healthy/unhealthy (case-insensitive), e.g. \"health\": \"Healthy \" with whitespace, or a foreign value like \"UP\".","commonSituations":"Producers using different enum vocabularies (e.g. Prometheus health strings in another format); typos or trailing whitespace; version skew adding new enum values unknown to the older decoder.","solutions":["Use exactly one of the supported values: \"unknown\", \"healthy\", \"unhealthy\" (case-insensitive).","Trim whitespace and control characters from the input before unmarshaling.","Align versions between producer and consumer so both share the same TargetHealth enum set.","Map foreign health vocabularies to TargetHealth values in a preprocessing step."],"exampleFix":"// before\n{\"health\": \"up\"}\n// after\n{\"health\": \"healthy\"}","handlingStrategy":"validation","validationCode":"const valid = ['unknown','healthy','unhealthy'];\nif (!valid.includes(health.trim().toLowerCase())) throw new Error('unknown targetHealth: '+health);","typeGuard":"func isTargetHealth(s string) bool {\n    _, ok := targetspb.TargetHealth_value[strings.ToUpper(strings.TrimSpace(s))]\n    return ok\n}","tryCatchPattern":"if err := json.Unmarshal(raw, &h); err != nil {\n    log.Warn(\"bad targetHealth, defaulting to unknown\")\n    h = targetspb.TargetHealth_UNKNOWN\n}","preventionTips":["Normalize case and trim whitespace before unmarshal","Keep enum sets in sync across service versions","Map external health vocabularies explicitly"],"tags":["json","enum","validation","thanos-targets"],"backgroundTag":"invalid-enum-value","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"}