Skip to content

fix(github): nil-check token source to avoid panic when no token configured#8298

Open
loispostula wants to merge 1 commit intoupdatecli:mainfrom
loispostula:fix/8297-github-token-nil-panic
Open

fix(github): nil-check token source to avoid panic when no token configured#8298
loispostula wants to merge 1 commit intoupdatecli:mainfrom
loispostula:fix/8297-github-token-nil-panic

Conversation

@loispostula
Copy link
Copy Markdown
Contributor

Fix #8297

GetTokenSourceFromConfig / GetTokenSourceFromEnv legitimately return a nil oauth2.TokenSource when nothing is configured. GetAccessToken called Token() on that nil source, panicking deep inside Clone instead of returning a usable error.

Test

To test this pull request, you can run the following commands:

cd pkg/plugins/scms/github/token
go test

A regression test TestGetAccessToken_NilTokenSource was added asserting GetAccessToken(nil) returns an error without panicking.

Additional Information

Checklist

  • I have updated the documentation via pull request in website repository.

Tradeoff

The error is still surfaced inside Clone rather than at SCM init time. Surfacing it earlier would be a larger change touching the GitHub SCM init path; this PR is the minimal fix to stop the panic.

Potential improvement

Detect "no token configured" at GitHub SCM init time and fail fast with an actionable message before reaching Clone.

…igured

GetTokenSourceFromConfig/Env legitimately return a nil oauth2.TokenSource
when nothing is configured. GetAccessToken called Token() on that nil
source, panicking deep inside Clone instead of returning a usable error.

Fixes updatecli#8297

Signed-off-by: Loïs Postula <lois@postu.la>
@loispostula loispostula requested a review from olblak April 7, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nil pointer panic in GetAccessToken when no GitHub token is configured

1 participant