{"record":{"id":"8444ca586becfc11","repo":"JuliusBrussee/caveman","slug":"githubapp-marshal-request-w","errorCode":null,"errorMessage":"githubapp: marshal request: %w","messagePattern":"githubapp: marshal request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":368,"sourceCode":"\t\treturn 0, nil, fmt.Errorf(\"githubapp: request path must be a single-host absolute path\")\n\t}\n\tbase, err := url.Parse(a.baseURL)\n\tif err != nil || base.Scheme == \"\" || base.Host == \"\" || base.User != nil {\n\t\treturn 0, nil, fmt.Errorf(\"githubapp: invalid base URL\")\n\t}\n\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()","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L350-L386","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\ntype req struct {\n    Callback func() `json:\"-\"`\n    Repo     string\n}\n// after\ntype req struct {\n    Repo string `json:\"repo\"`\n}","handlingStrategy":"validation","validationCode":"if b, err := json.Marshal(body); err != nil {\n    return fmt.Errorf(\"request body not serializable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if _, _, err := app.DoToken(ctx, tok, m, path, body); err != nil {\n    if strings.Contains(err.Error(), \"marshal request\") {\n        // remove non-serializable fields; do not retry\n    }\n}","preventionTips":["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."],"tags":["github","json","serialization"],"backgroundTag":"json-marshal-failed","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"}