JuliusBrussee/caveman · error

githubapp: decode repo

Error message

githubapp: decode repo: %w

What it means

GetRepo received HTTP 200 but the response body could not be parsed as JSON into the Repo struct. The underlying json.Unmarshal error is wrapped with %w so it can be inspected with errors.As/errors.Is.

Solutions

  1. Log the raw body (snippet) at debug level to see what was actually returned
  2. Use errors.As to unwrap and inspect the *json.UnmarshalTypeError / *json.SyntaxError
  3. Check for transparent proxies injecting HTML; call the GitHub API endpoint directly to compare
  4. Pin/inspect the Go type expectations in shared/platform/githubapp/githubapp.go against current GitHub API docs

Example fix

// before
if err := json.Unmarshal(raw, &r); err != nil { ... }
// after (caller-side unwrap)
var syn *json.SyntaxError
if errors.As(err, &syn) {
    log.Printf("invalid JSON at offset %d", syn.Offset)
}
Defensive patterns

Strategy: try-catch

Try / catch

var syn *json.SyntaxError
if errors.As(err, &syn) {
    log.Printf("repo response not JSON at offset %d — check proxy", syn.Offset)
} else if var te *json.UnmarshalTypeError; errors.As(err, &te) {
    log.Printf("repo response shape changed at %s", te.Field)
}

Prevention

When it happens

Trigger: GitHub returns a 200 whose body is not the expected repo JSON schema — e.g. a proxy/HTML error page with status 200, or a response shaped differently than expected.

Common situations: Corporate proxy or API gateway returning HTML with 200; GitHub API preview/behavior change; response truncated mid-stream.

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/48295ffee77cc045. Report an issue: GitHub.

Appendix: source

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

	FullName      string `json:"full_name"`
	DefaultBranch string `json:"default_branch"`
}

// GetRepo verifies that the installation token can see owner/name and returns the
// repo's stable node id + default branch. Used by select-repo to confirm the repo
// truly belongs to the installation before the binding goes 'active'.
func (a *App) GetRepo(ctx context.Context, token, owner, name string) (Repo, error) {
	status, raw, err := a.do(ctx, "Bearer "+token, http.MethodGet,
		"/repos/"+url.PathEscape(owner)+"/"+url.PathEscape(name), nil)
	if err != nil {
		return Repo{}, err
	}
	if status != http.StatusOK {
		return Repo{}, fmt.Errorf("githubapp: get repo %s/%s: HTTP %d: %s", owner, name, status, snippet(raw))
	}
	var r Repo
	if err := json.Unmarshal(raw, &r); err != nil {
		return Repo{}, fmt.Errorf("githubapp: decode repo: %w", err)
	}
	return r, nil
}

// 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
	}

View on GitHub (pinned to 3ee70a1026)