JuliusBrussee/caveman · error

githubapp: token response carried no token

Error message

githubapp: token response carried no token

What it means

The response decoded successfully but the token field was empty, meaning GitHub indicated success without actually issuing a credential. Since a tokenless response is useless and could indicate a broken flow, the library fails closed instead of returning an empty token.

Solutions

  1. Fix the fixture/mock to include a non-empty token field
  2. Log and inspect the raw response to confirm what GitHub returned
  3. If the empty token persists against real GitHub, file an issue — treat it as an API anomaly

Example fix

// before
{"expires_at": "2026-01-01T00:00:00Z"}
// after
{"token": "ghs_xxx", "expires_at": "2026-01-01T00:00:00Z"}
Defensive patterns

Strategy: try-catch

Validate before calling

// No pre-call validation; guard the returned token before use instead

Type guard

func usableToken(t githubapp.InstallationToken) bool { return t.Token != "" }

Try / catch

tok, err := app.MintInstallationToken(ctx, id, []string{repo}, nil)
if err != nil {
	if strings.Contains(err.Error(), "carried no token") {
		// log raw response; treat as upstream anomaly; retry once
	}
	return err
}
if !usableToken(tok) { return fmt.Errorf("no token issued") }

Prevention

When it happens

Trigger: App.MintInstallationToken receiving a 201 whose JSON parses but has an empty or missing "token" field — e.g. a malformed fixture, an interception layer echoing a partial body, or an unexpected GitHub-side condition.

Common situations: Hand-written test doubles returning {"expires_at":"..."} without the token field; proxies stripping fields; API behavior changes.

Understand the failure class

Background: "empty response", "returned no data", "empty embeddings": what HTTP 200-with-empty-body errors mean across libraries — this error's family across 36 libraries.

Related errors


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

Appendix: source

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

	jwt, err := a.AppJWT()
	if err != nil {
		return InstallationToken{}, err
	}
	body := map[string]any{"permissions": scopedPermissions, "repositories": []string{repository}}
	status, raw, err := a.do(ctx, "Bearer "+jwt, http.MethodPost,
		"/app/installations/"+strconv.FormatInt(installationID, 10)+"/access_tokens", body)
	if err != nil {
		return InstallationToken{}, err
	}
	if status != http.StatusCreated {
		return InstallationToken{}, fmt.Errorf("githubapp: mint token: HTTP %d: %s", status, snippet(raw))
	}
	var out InstallationToken
	if err := json.Unmarshal(raw, &out); err != nil {
		return InstallationToken{}, fmt.Errorf("githubapp: decode token response: %w", err)
	}
	if out.Token == "" {
		return InstallationToken{}, fmt.Errorf("githubapp: token response carried no token")
	}
	return out, nil
}

// RevokeToken DELETEs /installation/token authenticated with the token itself —
// the job-end "drop all agency" step. A best-effort revoke; the ~1h natural
// expiry is the backstop.
func (a *App) RevokeToken(ctx context.Context, token string) error {
	status, raw, err := a.do(ctx, "Bearer "+token, http.MethodDelete, "/installation/token", nil)
	if err != nil {
		return err
	}
	if status != http.StatusNoContent {
		return fmt.Errorf("githubapp: revoke token: HTTP %d: %s", status, snippet(raw))
	}
	return nil
}

View on GitHub (pinned to 3ee70a1026)