GoogleContainerTools/skaffold · error

creating github comment: %w

Error message

creating github comment: %w

What it means

Returned by Client.CommentOnPR in Skaffold's GitHub webhook when the GitHub API call Issues.CreateComment fails while posting a review comment on a pull request. The original GitHub client error is wrapped with %w so callers can unwrap and inspect the root cause (rate limits, auth, network).

Source

Thrown at pkg/webhook/github/github.go:64

	// Return a client instance from github
	client := github.NewClient(tc)
	return &Client{
		Client: client,
		ctx:    context.Background(),
	}
}

// CommentOnPR comments message on the PR
func (g *Client) CommentOnPR(pr *github.PullRequestEvent, message string) error {
	comment := &github.IssueComment{
		Body: &message,
	}

	log.Printf("Creating comment on PR %d: %s", pr.PullRequest.GetNumber(), message)
	_, _, err := g.Client.Issues.CreateComment(g.ctx, constants.GithubOwner, constants.GithubRepo, pr.PullRequest.GetNumber(), comment)
	if err != nil {
		return fmt.Errorf("creating github comment: %w", err)
	}
	log.Printf("Successfully commented on PR %d.", pr.GetNumber())
	return nil
}

// RemoveLabelFromPR removes label from pr
func (g *Client) RemoveLabelFromPR(pr *github.PullRequestEvent, label string) error {
	_, err := g.Client.Issues.RemoveLabelForIssue(g.ctx, constants.GithubOwner, constants.GithubRepo, pr.GetNumber(), label)
	if err != nil {
		return fmt.Errorf("deleting label: %w", err)
	}
	log.Printf("Successfully deleted label from PR %d", pr.GetNumber())
	return nil
}

View on GitHub (pinned to a1189de023)

Solutions

  1. Unwrap the error (`errors.Unwrap` / `errors.As`) and check the GitHub API status; fix auth if 401/403 or scopes if 404 on a private repo.
  2. Regenerate/refresh the GitHub token and grant it repo write (or `pull-requests: write` for fine-grained tokens).
  3. Verify constants.GithubOwner and constants.GithubRepo match the actual repository the PR belongs to.
  4. If 403 with rate-limit headers, add backoff/retry honoring X-RateLimit-Reset.
  5. Check network/proxy connectivity from the webhook host to api.github.com.

Example fix

// before
err := g.CommentOnPR(pr, msg)
// after
if err := g.CommentOnPR(pr, msg); err != nil {
    var ghErr *github.RateLimitError
    if errors.As(err, &ghErr) {
        time.Sleep(time.Until(ghErr.Rate.Reset.Time))
        err = g.CommentOnPR(pr, msg)
    }
    if err != nil { log.Printf("comment failed: %v", err) }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: verify token and repo access
resp, err := http.Get("https://api.github.com/repos/" + owner + "/" + repo)
// 404 => bad repo or token lacks access; abort before commenting

Try / catch

// Go
if err := g.CommentOnPR(pr, msg); err != nil {
    var rlErr *github.RateLimitError
    var respErr *github.ErrorResponse
    switch {
    case errors.As(err, &rlErr):
        time.Sleep(time.Until(rlErr.Rate.Reset.Time))
    case errors.As(err, &respErr) && respErr.Response.StatusCode == 401:
        // refresh token
    default:
        log.Printf("comment on PR failed: %v", err)
    }
}

Prevention

When it happens

Trigger: Calling CommentOnPR when the GitHub Issues API CreateComment request errors: invalid/expired token, missing repo write scope, wrong owner/repo constants, PR number no longer valid, or network failure.

Common situations: Webhook runs in CI with a GITHUB_TOKEN lacking `repo` or pull-request write scopes; token expired; hitting secondary rate limits from automated commenting; repository renamed/transferred so constants.GithubOwner/GithubRepo no longer match.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/a2e00c03786a9848. Report an issue: GitHub.