Skip to content

fix(github): handle error before variable assignment#7593

Merged
olblak merged 3 commits intoupdatecli:mainfrom
olblak:issue/7587
Jan 22, 2026
Merged

fix(github): handle error before variable assignment#7593
olblak merged 3 commits intoupdatecli:mainfrom
olblak:issue/7587

Conversation

@olblak
Copy link
Member

@olblak olblak commented Jan 21, 2026

Fix #7587

Correctly handle error before assignment variable

Test

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

/

Additional Information

Checklist

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

Tradeoff

Potential improvement

@olblak olblak added the bug Something isn't working label Jan 21, 2026
@olblak olblak requested a review from Copilot January 21, 2026 20:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a bug where error handling was performed after attempting to use a potentially nil pointer. The code now correctly checks for errors from client.New() before using the returned clientConfig.

Changes:

  • Moved error check before variable assignment to prevent nil pointer dereference
  • Added nil check before using clientConfig fields (though this is unnecessary)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +325 to +330
if clientConfig != nil {
g.client = clientConfig.Client
g.username = clientConfig.Username
g.token = clientConfig.TokenSource
g.URL = clientConfig.URL
}
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nil check for clientConfig is unnecessary. When client.New returns an error (checked at line 321), it always returns nil for the clientConfig, and the function returns early at line 322. This code block is only reached when err is nil, and when client.New succeeds (err == nil), it always returns a non-nil ClientConfig pointer. The nil check should be removed and the fields should be assigned directly.

Suggested change
if clientConfig != nil {
g.client = clientConfig.Client
g.username = clientConfig.Username
g.token = clientConfig.TokenSource
g.URL = clientConfig.URL
}
g.client = clientConfig.Client
g.username = clientConfig.Username
g.token = clientConfig.TokenSource
g.URL = clientConfig.URL

Copilot uses AI. Check for mistakes.
@olblak olblak merged commit 7e31c8c into updatecli:main Jan 22, 2026
5 checks passed
@olblak olblak changed the title fix: handle error before variable assignment fix: handle error before variable assignment in github scm Jan 27, 2026
@olblak olblak changed the title fix: handle error before variable assignment in github scm fix(github): handle error before variable assignment Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

github scm runtime panic

2 participants