JuliusBrussee/caveman · error

githubapp: decode repository proof

Error message

githubapp: decode repository proof: %w

What it means

Wrapped decode error from GetFileContent: the repository-contents response downloaded fine but its JSON payload could not be unmarshalled into the proof struct (type/encoding/content/size fields). Included via %w so the underlying json error stays visible.

Solutions

  1. Log the raw response body and unwrap with errors.As (*json.SyntaxError / *json.UnmarshalTypeError)
  2. Bypass proxies and call api.github.com directly to isolate middlebox interference
  3. Compare the payload against the GitHub contents-API schema and update the struct if changed
  4. Retry on transient truncation; persist raw bytes for postmortem if it recurs
Defensive patterns

Strategy: try-catch

Try / catch

var syn *json.SyntaxError
if errors.As(err, &syn) {
    log.Printf("contents payload not JSON (offset %d) — bypass proxy and retry", syn.Offset)
} else {
    return fmt.Errorf("contents schema drift: %w", err)
}

Prevention

When it happens

Trigger: A 200 body that is not the expected {type, encoding, content, size} object — e.g. HTML injected by a proxy with 200, truncated response, or GitHub schema change to the contents payload.

Common situations: Intercepting proxies/inspectors returning success pages; network truncation; API shape drift on /contents endpoint.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/6b7bd21b3b338ed8. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/githubapp/githubapp.go:325

	endpoint := "/repos/" + url.PathEscape(owner) + "/" + url.PathEscape(name) + "/contents/" + strings.Join(segments, "/")
	if strings.TrimSpace(ref) != "" {
		endpoint += "?" + url.Values{"ref": {ref}}.Encode()
	}
	status, raw, err := a.do(ctx, "Bearer "+token, http.MethodGet, endpoint, nil)
	if err != nil {
		return nil, err
	}
	if status != http.StatusOK {
		return nil, fmt.Errorf("githubapp: get repository proof: HTTP %d: %s", status, snippet(raw))
	}
	var payload struct {
		Type     string `json:"type"`
		Encoding string `json:"encoding"`
		Content  string `json:"content"`
		Size     int64  `json:"size"`
	}
	if err := json.Unmarshal(raw, &payload); err != nil {
		return nil, fmt.Errorf("githubapp: decode repository proof: %w", err)
	}
	if payload.Type != "file" || payload.Encoding != "base64" || payload.Size < 0 || payload.Size > 64<<10 {
		return nil, fmt.Errorf("githubapp: repository proof has invalid type, encoding, or size")
	}
	decoded, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(payload.Content, "\n", ""))
	if err != nil {
		return nil, fmt.Errorf("githubapp: decode repository proof content: %w", err)
	}
	if len(decoded) > 64<<10 || int64(len(decoded)) != payload.Size {
		return nil, fmt.Errorf("githubapp: repository proof size mismatch")
	}
	return decoded, nil
}

// DoToken issues an authenticated GitHub REST call with an installation token and
// returns the status + raw body for the caller to parse. It is the reusable
// primitive the worker's PR opener builds the Git Data API flow on, so every
// GitHub egress goes through the one SSRF-guarded client + fixed base host.

View on GitHub (pinned to 3ee70a1026)