JuliusBrussee/caveman · error

githubapp: decode repo installation

Error message

githubapp: decode repo installation: %w

What it means

Wrapped decode error from GetRepoInstallation: the GitHub API call for /repos/{owner}/{name}/installation succeeded (HTTP 200) but the JSON body could not be unmarshalled into the Installation struct. The decode error is included via %w; the API response shape was not what the client expects.

Solutions

  1. Unwrap with errors.As to distinguish SyntaxError vs TypeMismatchError and log the raw body at debug level
  2. Compare the actual response fields with the Installation struct's JSON tags
  3. Bypass proxies/VPNs and hit api.github.com directly to reproduce
  4. Update struct definitions if GitHub changed the installation payload shape
Defensive patterns

Strategy: try-catch

Try / catch

var syn *json.SyntaxError
if errors.As(err, &syn) {
    log.Printf("installation payload not JSON — inspect proxy/response body")
}

Prevention

When it happens

Trigger: A 200 response whose body is not valid Installation JSON — proxy-injected HTML with 200, GitHub schema change to the installation object, or truncated body.

Common situations: Middleboxes returning success pages; API changes on the /installation endpoint; misrouted request hitting a login page (200 HTML).

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/63be767fb29b14bf. Report an issue: GitHub.

Appendix: source

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

// GetRepoInstallation asks GitHub which installation of this App owns access to
// a repository. This avoids treating public repository visibility as proof that
// a caller-supplied installation id is authorized for that repository.
func (a *App) GetRepoInstallation(ctx context.Context, owner, name string) (Installation, error) {
	var out Installation
	jwt, err := a.AppJWT()
	if err != nil {
		return out, err
	}
	status, raw, err := a.do(ctx, "Bearer "+jwt, http.MethodGet,
		"/repos/"+url.PathEscape(owner)+"/"+url.PathEscape(name)+"/installation", nil)
	if err != nil {
		return out, err
	}
	if status != http.StatusOK {
		return out, fmt.Errorf("githubapp: get repo installation %s/%s: HTTP %d: %s", owner, name, status, snippet(raw))
	}
	if err := json.Unmarshal(raw, &out); err != nil {
		return out, fmt.Errorf("githubapp: decode repo installation: %w", err)
	}
	if out.ID <= 0 {
		return Installation{}, fmt.Errorf("githubapp: repo installation response carried no id")
	}
	return out, nil
}

// GetFileContent reads one repository file with an installation token. The
// content endpoint returns base64; callers receive decoded bytes with a strict
// 64 KiB post-decode ceiling because connection proofs are tiny text files.
func (a *App) GetFileContent(ctx context.Context, token, owner, name, path, ref string) ([]byte, error) {
	segments := strings.Split(strings.Trim(path, "/"), "/")
	if len(segments) == 0 || segments[0] == "" {
		return nil, fmt.Errorf("githubapp: content path is required")
	}
	for i := range segments {
		segments[i] = url.PathEscape(segments[i])
	}

View on GitHub (pinned to 3ee70a1026)