{"record":{"id":"99f5c4f069aeafc9","repo":"thanos-io/thanos","slug":"targethealth-unquote-v","errorCode":null,"errorMessage":"targetHealth: unquote %v","messagePattern":"targetHealth: unquote (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/targets/targetspb/custom.go","lineNumber":35,"sourceCode":"\treturn &TargetsResponse{\n\t\tResult: &TargetsResponse_Targets{\n\t\t\tTargets: targets,\n\t\t},\n\t}\n}\n\nfunc NewWarningTargetsResponse(warning error) *TargetsResponse {\n\treturn &TargetsResponse{\n\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","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/targets/targetspb/custom.go#L17-L53","documentation":"TargetHealth is a custom enum type that unmarshals from a JSON string. This error wraps strconv.Unquote failing, meaning the JSON value for targetHealth was not a properly quoted string (or was malformed JSON text).","triggerScenarios":"TargetHealth.UnmarshalJSON receives bytes that are not a valid JSON string literal, so strconv.Unquote fails — e.g. unquoted value like healthy or a number.","commonSituations":"Hand-edited or generated JSON where health is emitted unquoted; a client marshaling TargetHealth as a raw number; custom tooling writing struct fields directly to JSON.","solutions":["Fix the JSON input so targetHealth is a quoted string, e.g. \"health\": \"healthy\" instead of health: healthy.","Ensure producers use TargetHealth.MarshalJSON instead of serializing the enum as an int.","If parsing third-party JSON, preprocess/normalize the field to a quoted string before unmarshal.","Check the value reported in the error message (entry) to see the exact malformed token."],"exampleFix":"// before\n{\"health\": healthy}\n// after\n{\"health\": \"healthy\"}","handlingStrategy":"validation","validationCode":"let health = data.health;\nif (typeof health !== 'string') throw new Error('targetHealth must be a JSON string');","typeGuard":"function isQuotedJSONString(v string) bool { return len(v) >= 2 && v[0] == '\"' && v[len(v)-1] == '\"' }","tryCatchPattern":"var h targetspb.TargetHealth\nif err := json.Unmarshal(raw, &h); err != nil {\n    return fmt.Errorf(\"bad targetHealth %q: %w\", raw, err)\n}","preventionTips":["Always emit targetHealth via TargetHealth.MarshalJSON","Reject unquoted enum values in ingestion pipelines early","Round-trip test fixtures through Marshal/Unmarshal"],"tags":["json","unmarshal","enum","thanos-targets"],"backgroundTag":"invalid-json-response","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"}