{"record":{"id":"9a905e1ef10ec4c1","repo":"thanos-io/thanos","slug":"invalid-targets-parameter-state-v","errorCode":null,"errorMessage":"invalid targets parameter state='%v'","messagePattern":"invalid targets parameter state='(.+?)'","errorType":"http","errorClass":"ApiError","httpStatus":400,"severity":"error","filePath":"pkg/api/query/v1.go","lineNumber":1388,"sourceCode":"\t\tstatuses[status.ComponentType.String()] = append(statuses[status.ComponentType.String()], filteredStatus)\n\t}\n\treturn statuses, nil, nil, func() {}\n}\n\n// NewTargetsHandler created handler compatible with HTTP /api/v1/targets https://prometheus.io/docs/prometheus/latest/querying/api/#targets\n// which uses gRPC Unary Targets API.\nfunc NewTargetsHandler(client targets.UnaryClient, enablePartialResponse bool) func(*http.Request) (any, []error, *api.ApiError, func()) {\n\tps := storepb.PartialResponseStrategy_ABORT\n\tif enablePartialResponse {\n\t\tps = storepb.PartialResponseStrategy_WARN\n\t}\n\n\treturn func(r *http.Request) (any, []error, *api.ApiError, func()) {\n\t\tstateParam := r.URL.Query().Get(\"state\")\n\t\tstate, ok := targetspb.TargetsRequest_State_value[strings.ToUpper(stateParam)]\n\t\tif !ok {\n\t\t\tif stateParam != \"\" {\n\t\t\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: errors.Errorf(\"invalid targets parameter state='%v'\", stateParam)}, func() {}\n\t\t\t}\n\t\t\tstate = int32(targetspb.TargetsRequest_ANY)\n\t\t}\n\n\t\treq := &targetspb.TargetsRequest{\n\t\t\tState:                   targetspb.TargetsRequest_State(state),\n\t\t\tPartialResponseStrategy: ps,\n\t\t}\n\n\t\tt, warnings, err := client.Targets(r.Context(), req)\n\t\tif err != nil {\n\t\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorInternal, Err: errors.Wrap(err, \"retrieving targets\")}, func() {}\n\t\t}\n\n\t\treturn t, warnings.AsErrors(), nil, func() {}\n\t}\n}\n","sourceCodeStart":1370,"sourceCodeEnd":1406,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/api/query/v1.go#L1370-L1406","documentation":"This error is returned by the Thanos Query API's /targets endpoint when the 'state' query parameter contains a value that does not map to any known TargetsRequest_State enum value (ANY, ACTIVE, DROPPED, UNHEALTHY). The handler looks up strings.ToUpper(stateParam) in the generated protobuf enum map, and only throws when a non-empty value was supplied that isn't in the map. It is a client-side input validation error (ErrorBadData, HTTP 400).","triggerScenarios":"GET /api/v1/targets?state=foo with any value other than (case-insensitively) ANY, ACTIVE, DROPPED, or UNHEALTHY.","commonSituations":"Typo like 'state=acitve', passing 'all' instead of 'any', passing free-form text scraped from another Prometheus-like API that uses different state names, or scripting against the endpoint without checking the protobuf enum values.","solutions":["Use one of the allowed values, case-insensitively: any, active, dropped, unhealthy.","Omit the 'state' parameter entirely to default to ANY.","Check the TargetsRequest_State enum in pkg/targets/targetspb (targets.proto) for the authoritative list of values."],"exampleFix":"// before\ncurl 'http://query:9090/api/v1/targets?state=down'\n// after\ncurl 'http://query:9090/api/v1/targets?state=unhealthy'","handlingStrategy":"validation","validationCode":"const allowed = ['any','active','dropped','unhealthy'];\nconst state = params.get('state');\nif (state && !allowed.includes(state.toLowerCase())) throw new Error(`invalid state='${state}'; use one of ${allowed.join(',')}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Whitelist state values client-side against the TargetsRequest_State enum.","Omit the param when you want all targets.","Keep a shared constant list of allowed states in your client code."],"tags":["http","api","validation","enum"],"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"}