{"record":{"id":"c001fb830f897577","repo":"thanos-io/thanos","slug":"error-parsing-request-form-v","errorCode":null,"errorMessage":"error parsing request form='%v'","messagePattern":"error parsing request form='(.+?)'","errorType":"http","errorClass":"ApiError","httpStatus":500,"severity":"error","filePath":"pkg/api/query/v1.go","lineNumber":1481,"sourceCode":"\t\tdefer span.Finish()\n\n\t\tvar (\n\t\t\tgroups   *rulespb.RuleGroups\n\t\t\twarnings annotations.Annotations\n\t\t\terr      error\n\t\t)\n\n\t\ttypeParam := r.URL.Query().Get(\"type\")\n\t\ttyp, ok := rulespb.RulesRequest_Type_value[strings.ToUpper(typeParam)]\n\t\tif !ok {\n\t\t\tif typeParam != \"\" {\n\t\t\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: errors.Errorf(\"invalid rules parameter type='%v'\", typeParam)}, func() {}\n\t\t\t}\n\t\t\ttyp = int32(rulespb.RulesRequest_ALL)\n\t\t}\n\n\t\tif err := r.ParseForm(); err != nil {\n\t\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorInternal, Err: errors.Errorf(\"error parsing request form='%v'\", MatcherParam)}, func() {}\n\t\t}\n\n\t\t// TODO(bwplotka): Allow exactly the same functionality as query API: passing replica, dedup and partial response as HTTP params as well.\n\t\treq := &rulespb.RulesRequest{\n\t\t\tType:                    rulespb.RulesRequest_Type(typ),\n\t\t\tPartialResponseStrategy: ps,\n\t\t\tMatcherString:           r.Form[MatcherParam],\n\t\t\tRuleName:                r.Form[RuleNameParam],\n\t\t\tRuleGroup:               r.Form[RuleGroupParam],\n\t\t\tFile:                    r.Form[FileParam],\n\t\t}\n\t\ttracing.DoInSpan(ctx, \"retrieve_rules\", func(ctx context.Context) {\n\t\t\tgroups, warnings, err = client.Rules(ctx, req)\n\t\t})\n\t\tif err != nil {\n\t\t\treturn nil, nil, &api.ApiError{Typ: api.ErrorInternal, Err: errors.Errorf(\"error retrieving rules: %v\", err)}, func() {}\n\t\t}\n\t\treturn groups, warnings.AsErrors(), nil, func() {}","sourceCodeStart":1463,"sourceCodeEnd":1499,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/api/query/v1.go#L1463-L1499","documentation":"Returned when r.ParseForm() fails while handling the /api/v1/rules request. ParseForm parses the URL query and (for POST) the body; a malformed query string or unreadable body triggers this. Note a copy-paste quirk: the error text interpolates the MatcherParam constant rather than the actual parse error, and it is surfaced as ErrorInternal (HTTP 500).","triggerScenarios":"Any /api/v1/rules request whose URL query string or form body cannot be parsed by net/http — e.g. malformed percent-encoding like '%zz' in the query.","commonSituations":"Hand-crafted URLs with invalid percent-escapes, proxies mangling the query string, or clients sending a corrupt/malformed POST body to the rules endpoint.","solutions":["URL-encode query parameters properly (e.g. use url.Values.Encode / encodeURIComponent for match[] regexes).","Remove or fix malformed percent-escapes in the request URL.","Inspect the wrapped ParseForm error from the HTTP layer for the precise parse failure.","If the confusing message (which prints the param name, not the cause) is a problem, patch v1.go to wrap the actual err."],"exampleFix":"// before\nfetch('/api/v1/rules?match[]=' + expr)\n// after\nfetch('/api/v1/rules?match[]=' + encodeURIComponent(expr))","handlingStrategy":"validation","validationCode":"const qs = new URLSearchParams(); qs.set('match[]', expr); const url = `/api/v1/rules?${qs.toString()}`; // ensures valid percent-encoding","typeGuard":null,"tryCatchPattern":"try { const r = await fetch(url); if (!r.ok) throw new Error(await r.text()); } catch (e) { console.error('rules request failed:', e.message); }","preventionTips":["Always build query strings with a URL-encoding helper, never string concatenation.","Validate match[] regexes before encoding them.","Avoid POSTing odd bodies to GET-style API endpoints."],"tags":["http","api","parsing"],"backgroundTag":"invalid-query-parameter","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"}