JuliusBrussee/caveman · error
githubapp: build request
Error message
githubapp: build request: %w
What it means
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.
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.
Example fix
// before
client.DoToken(ctx, tok, strings.ToUpper(cfg.Method), path, body) // cfg.Method = "GET \n"
// after
if cfg.Method != "GET" && cfg.Method != "POST" && cfg.Method != "PATCH" && cfg.Method != "DELETE" {
return fmt.Errorf("unsupported method %q", cfg.Method)
}
client.DoToken(ctx, tok, cfg.Method, strings.TrimSpace(path), body) Defensive patterns
Strategy: validation
Validate before calling
var allowed = map[string]bool{"GET": true, "POST": true, "PATCH": true, "PUT": true, "DELETE": true}
if !allowed[method] || strings.TrimSpace(method) != method {
return fmt.Errorf("invalid HTTP method %q", method)
} Try / catch
if _, _, err := app.DoToken(ctx, tok, method, path, body); err != nil {
if strings.Contains(err.Error(), "build request") {
// fix method/path at the call site; do not retry
}
} Prevention
- 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.
When it happens
Trigger: 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 " is not); a target URL with control characters or malformed percent-encoding that survived to this stage.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- githubapp: get repo / : HTTP
- githubapp: get repository proof: HTTP
- githubapp: revoke token: HTTP
- awscreds: build sts request
- awscreds: : http
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/8eaa004375b52d5b.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/githubapp/githubapp.go:374
relative, err := url.ParseRequestURI(path)
if err != nil || relative.IsAbs() || relative.Host != "" || relative.User != nil {
return 0, nil, fmt.Errorf("githubapp: invalid request path")
}
target, err := url.Parse(a.baseURL + path)
if err != nil || target.Scheme != base.Scheme || !strings.EqualFold(target.Host, base.Host) || target.User != nil {
return 0, nil, fmt.Errorf("githubapp: request path escaped configured host")
}
var reader io.Reader
if body != nil {
b, err := json.Marshal(body)
if err != nil {
return 0, nil, fmt.Errorf("githubapp: marshal request: %w", err)
}
reader = bytes.NewReader(b)
}
req, err := http.NewRequestWithContext(ctx, method, target.String(), reader)
if err != nil {
return 0, nil, fmt.Errorf("githubapp: build request: %w", err)
}
req.Header.Set("Authorization", authorization)
req.Header.Set("Accept", "application/vnd.github+json")
req.Header.Set("X-GitHub-Api-Version", "2022-11-28")
if body != nil {
req.Header.Set("Content-Type", "application/json")
}
resp, err := a.httpClient.Do(req)
if err != nil {
return 0, nil, fmt.Errorf("githubapp: request failed: %w", err)
}
defer resp.Body.Close()
raw, err := io.ReadAll(io.LimitReader(resp.Body, 4<<20))
if err != nil {
return resp.StatusCode, nil, fmt.Errorf("githubapp: read response: %w", err)
}
return resp.StatusCode, raw, nil
}View on GitHub (pinned to 3ee70a1026)