JuliusBrussee/caveman · error

githubapp: decode installation

Error message

githubapp: decode installation: %w

What it means

The endpoint returned HTTP 200 but the body could not be parsed as the expected Installation JSON. The library wraps the json.Unmarshal error with this prefix. This indicates GitHub's response did not match the expected schema or was truncated/corrupted.

Solutions

  1. Log the raw body (it is in the wrapped error chain) to see what was actually returned
  2. If behind a proxy, bypass it or fix its response content type
  3. Update the library if GitHub changed the response schema
  4. In tests, fix the fixture so it matches the real /app/installations/{id} payload
Defensive patterns

Strategy: retry

Validate before calling

// No pre-call validation possible; ensure no proxy rewrites api.github.com responses

Type guard

func isDecodeErr(err error) bool {
	return err != nil && strings.Contains(err.Error(), "decode installation:")
}

Try / catch

inst, err := app.GetInstallation(ctx, id)
if err != nil {
	if isDecodeErr(err) {
		log.Printf("unexpected installation payload: %v", err)
		// inspect raw body / bypass proxy; retry once
	}
	return err
}

Prevention

When it happens

Trigger: App.GetInstallation receives a 200 whose body is not valid JSON or does not match the Installation struct (e.g. an HTML error page, an empty body, or a proxy/interception layer returning unexpected content).

Common situations: Corporate proxies or API mocks returning HTML; GitHub returning an unusual payload during API changes; a test server returning the wrong fixture shape.

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/6e4169981cadaecb. Report an issue: GitHub.

Appendix: source

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

func (a *App) GetInstallation(ctx context.Context, installationID int64) (Installation, error) {
	var out Installation
	if installationID <= 0 {
		return out, fmt.Errorf("githubapp: installation id must be positive")
	}
	jwt, err := a.AppJWT()
	if err != nil {
		return out, err
	}
	status, raw, err := a.do(ctx, "Bearer "+jwt, http.MethodGet,
		"/app/installations/"+strconv.FormatInt(installationID, 10), nil)
	if err != nil {
		return out, err
	}
	if status != http.StatusOK {
		return out, fmt.Errorf("githubapp: get installation: HTTP %d: %s", status, snippet(raw))
	}
	if err := json.Unmarshal(raw, &out); err != nil {
		return out, fmt.Errorf("githubapp: decode installation: %w", err)
	}
	if out.ID != installationID || out.Account.ID <= 0 || strings.TrimSpace(out.Account.Login) == "" {
		return Installation{}, fmt.Errorf("githubapp: installation response identity mismatch")
	}
	return out, nil
}

// MintInstallationToken POSTs /app/installations/{id}/access_tokens narrowed to
// `repos` and `perms`, returning a ~1h token. Defaults (perms nil) are
// contents:write + pull_requests:write — enough to push a branch and open a draft
// PR, never to merge.
func (a *App) MintInstallationToken(ctx context.Context, installationID int64, repos []string, perms map[string]string) (InstallationToken, error) {
	if installationID <= 0 {
		return InstallationToken{}, fmt.Errorf("githubapp: installation id must be positive")
	}
	if len(repos) != 1 || strings.TrimSpace(repos[0]) == "" {
		return InstallationToken{}, fmt.Errorf("githubapp: exactly one repository is required")
	}

View on GitHub (pinned to 3ee70a1026)