cilium/cilium · error

creating github client: %w

Error message

creating github client: %w

What it means

`github.NewClient(github.WithAuthToken(token))` (go-github) returned an error while constructing the authenticated client in `downloadWorkflowData`. This is rare — it generally means the auth credential itself was rejected at construction time (e.g. invalid token string) rather than an API/network problem.

Source

Thrown at cilium-cli/features/summary.go:63

	return s.printSummaryFromJsons(workflowData)
}

func (s *Feature) downloadWorkflowData(ctx context.Context) error {
	token := os.Getenv("GITHUB_TOKEN")

	if token == "" {
		return fmt.Errorf("GITHUB_TOKEN environment variable must be set.")
	}

	parts := strings.Split(s.params.Repo, "/")
	if len(parts) != 2 {
		return fmt.Errorf("invalid repository format. Expected 'owner/repo', got '%s'", s.params.Repo)
	}
	owner, repoName := parts[0], parts[1]

	ghClient, err := github.NewClient(github.WithAuthToken(token))
	if err != nil {
		return fmt.Errorf("creating github client: %w", err)
	}

	allRuns := map[int64]*github.WorkflowRun{}
	// Fetch workflow runs for the specific commit
	for _, event := range []string{"push", "schedule", "pull_request", "pull_request_target"} {
		opts := &github.ListWorkflowRunsOptions{
			HeadSHA: s.params.Commit,
			Status:  "completed",
			Event:   event,
			ListOptions: github.ListOptions{
				PerPage: 100,
			},
		}

		for {
			runs, resp, err := ghClient.Actions.ListRepositoryWorkflowRuns(ctx, owner, repoName, opts)
			if err != nil {
				return fmt.Errorf("failed to fetch workflow runs: %w", err)

View on GitHub (pinned to ac7b90affa)

Solutions

  1. Re-export GITHUB_TOKEN from a trusted source without surrounding quotes/whitespace: `export GITHUB_TOKEN=$(gh auth token)`
  2. Regenerate the token and confirm it is a valid GitHub token format
  3. If using a fine-grained/App token, verify the go-github version supports it and upgrade dependencies if needed

Example fix

// before
export GITHUB_TOKEN=" ghp_xxx\n"
// after
export GITHUB_TOKEN=$(gh auth token)
Defensive patterns

Strategy: validation

Validate before calling

token := os.Getenv("GITHUB_TOKEN")
token = strings.TrimSpace(token)
if token == "" || strings.ContainsAny(token, "\n\r\x00") ||
	!(strings.HasPrefix(token, "ghp_") || strings.HasPrefix(token, "github_pat_") || strings.HasPrefix(token, "ghs_")) {
	return errors.New("GITHUB_TOKEN is not a valid GitHub token string")
}

Type guard

func validTokenFormat(t string) bool {
	t = strings.TrimSpace(t)
	return len(t) > 20 && !strings.ContainsAny(t, " \n\r\t\x00")
}

Try / catch

err := feat.GenSummary(ctx)
if err != nil && strings.Contains(err.Error(), "creating github client") {
	return fmt.Errorf("re-check GITHUB_TOKEN contents (quotes/whitespace?): %w", err)
}

Prevention

When it happens

Trigger: github.NewClient with WithAuthToken(token) fails on the supplied GITHUB_TOKEN value, e.g. malformed or control-character-containing token string.

Common situations: Token pasted with stray whitespace/newlines or quotes from a misconfigured secret; empty-but-set token corner cases; incompatible token format for the client version.

Related errors


AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31). Data as JSON: /api/errors/6df5103ae6105144. Report an issue: GitHub.