{"record":{"id":"8eaa004375b52d5b","repo":"JuliusBrussee/caveman","slug":"githubapp-build-request-w","errorCode":null,"errorMessage":"githubapp: build request: %w","messagePattern":"githubapp: build request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":374,"sourceCode":"\trelative, err := url.ParseRequestURI(path)\n\tif err != nil || relative.IsAbs() || relative.Host != \"\" || relative.User != nil {\n\t\treturn 0, nil, fmt.Errorf(\"githubapp: invalid request path\")\n\t}\n\ttarget, err := url.Parse(a.baseURL + path)\n\tif err != nil || target.Scheme != base.Scheme || !strings.EqualFold(target.Host, base.Host) || target.User != nil {\n\t\treturn 0, nil, fmt.Errorf(\"githubapp: request path escaped configured host\")\n\t}\n\tvar reader io.Reader\n\tif body != nil {\n\t\tb, err := json.Marshal(body)\n\t\tif err != nil {\n\t\t\treturn 0, nil, fmt.Errorf(\"githubapp: marshal request: %w\", err)\n\t\t}\n\t\treader = bytes.NewReader(b)\n\t}\n\treq, err := http.NewRequestWithContext(ctx, method, target.String(), reader)\n\tif err != nil {\n\t\treturn 0, nil, fmt.Errorf(\"githubapp: build request: %w\", err)\n\t}\n\treq.Header.Set(\"Authorization\", authorization)\n\treq.Header.Set(\"Accept\", \"application/vnd.github+json\")\n\treq.Header.Set(\"X-GitHub-Api-Version\", \"2022-11-28\")\n\tif body != nil {\n\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t}\n\tresp, err := a.httpClient.Do(req)\n\tif err != nil {\n\t\treturn 0, nil, fmt.Errorf(\"githubapp: request failed: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\traw, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))\n\tif err != nil {\n\t\treturn resp.StatusCode, nil, fmt.Errorf(\"githubapp: read response: %w\", err)\n\t}\n\treturn resp.StatusCode, raw, nil\n}","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L356-L392","documentation":"After building the target URL and serializing the body, do() constructs the outgoing request with http.NewRequestWithContext. This error wraps any failure from that constructor — most commonly an invalid HTTP method, or a URL that NewRequest's stricter parser rejects even after the earlier guards.","triggerScenarios":"Calling DoToken with a method string containing invalid characters (e.g. \"GET\\n\" or lowercase schemes like \"get\" with a body confusion, or \"FETCH\" is fine but \"GET\t\" is not); a target URL with control characters or malformed percent-encoding that survived to this stage.","commonSituations":"Building the HTTP verb from user input or config without validating it; passing a method with whitespace from a YAML/env config; extremely unusual percent-encodings in path segments.","solutions":["Validate the method string: pass canonical constants http.MethodGet, http.MethodPost, etc.","Trim whitespace from both method and path before calling DoToken.","If the method comes from config, whitelist it against the known verb set.","Re-run with the wrapped error printed; NewRequestWithContext reports the exact URL parse problem."],"exampleFix":"// before\nclient.DoToken(ctx, tok, strings.ToUpper(cfg.Method), path, body) // cfg.Method = \"GET \\n\"\n// after\nif cfg.Method != \"GET\" && cfg.Method != \"POST\" && cfg.Method != \"PATCH\" && cfg.Method != \"DELETE\" {\n    return fmt.Errorf(\"unsupported method %q\", cfg.Method)\n}\nclient.DoToken(ctx, tok, cfg.Method, strings.TrimSpace(path), body)","handlingStrategy":"validation","validationCode":"var allowed = map[string]bool{\"GET\": true, \"POST\": true, \"PATCH\": true, \"PUT\": true, \"DELETE\": true}\nif !allowed[method] || strings.TrimSpace(method) != method {\n    return fmt.Errorf(\"invalid HTTP method %q\", method)\n}","typeGuard":null,"tryCatchPattern":"if _, _, err := app.DoToken(ctx, tok, method, path, body); err != nil {\n    if strings.Contains(err.Error(), \"build request\") {\n    \t// fix method/path at the call site; do not retry\n    }\n}","preventionTips":["Use http.Method* constants instead of raw strings from config.","Trim whitespace from externally sourced method/path values.","Whitelist HTTP verbs when they come from configuration."],"tags":["github","http","request-construction"],"backgroundTag":"invalid-argument-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}