JuliusBrussee/caveman · error
githubapp: marshal request
Error message
githubapp: marshal request: %w
What it means
When a request body is supplied, do() serializes it with json.Marshal before sending. This error wraps any marshal failure. In practice Go's json.Marshal on a plain request struct essentially never fails, so hitting this indicates the body contains values that cannot be represented as JSON — channels, funcs, cyclic pointers, or invalid types.
Solutions
- Inspect the wrapped error for the unsupported Go type and remove or replace that field in the request body struct.
- Pre-marshal the body yourself (json.Marshal) in a test to reproduce and locate the offending field.
- Replace func/chan fields with serializable representations (e.g. string identifiers).
- Add a MarshalJSON guard or omitempty tags on fields that should never be serialized.
Example fix
// before
type req struct {
Callback func() `json:"-"`
Repo string
}
// after
type req struct {
Repo string `json:"repo"`
} Defensive patterns
Strategy: validation
Validate before calling
if b, err := json.Marshal(body); err != nil {
return fmt.Errorf("request body not serializable: %w", err)
} Try / catch
if _, _, err := app.DoToken(ctx, tok, m, path, body); err != nil {
if strings.Contains(err.Error(), "marshal request") {
// remove non-serializable fields; do not retry
}
} Prevention
- Keep request body structs free of chan/func/cyclic fields.
- Pre-marshal bodies in unit tests to catch issues early.
- Use json:"-" and omitempty tags on non-serializable members.
When it happens
Trigger: Calling DoToken/GetInstallation/MintInstallationToken-family methods whose body struct (or a value reachable from it) contains a chan, func, complex number, or a reference cycle that json.Marshal rejects.
Common situations: Passing a struct with a func or callback field added during refactoring; embedding a sync.WaitGroup or logger with unexported cycles; custom MarshalJSON returning a value that recurses infinitely.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- assembly slot content is not JSON-serializable
- assembly slot content is not JSON-serializable
- cave_sandbox_failure_not_serializable
- caveman agent: value is not canonically serializable
- encode before evidence
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/8444ca586becfc11.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/githubapp/githubapp.go:368
return 0, nil, fmt.Errorf("githubapp: request path must be a single-host absolute path")
}
base, err := url.Parse(a.baseURL)
if err != nil || base.Scheme == "" || base.Host == "" || base.User != nil {
return 0, nil, fmt.Errorf("githubapp: invalid base URL")
}
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()View on GitHub (pinned to 3ee70a1026)