Skip to content

Commit e8799ad

Browse files
committed
Handle race condition when authenticating to the CLI
1 parent 20a0623 commit e8799ad

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • extensions/ql-vscode/src

extensions/ql-vscode/src/cli.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,17 @@ export class CodeQLCliServer implements Disposable {
619619
progressReporter,
620620
async (line) => {
621621
if (line.startsWith("Enter value for --github-auth-stdin")) {
622-
return credentials.getAccessToken();
622+
try {
623+
return await credentials.getAccessToken();
624+
} catch (e) {
625+
// If the user cancels the authentication prompt, we still need to give a value to the CLI.
626+
// By giving a potentially invalid value, the user will just get a 401/403 when they try to access a
627+
// private package and the access token is invalid.
628+
// This code path is very rare to hit. It would only be hit if the user is logged in when
629+
// starting the command, then logging out before the getAccessToken() is called again and
630+
// then cancelling the authentication prompt.
631+
return accessToken;
632+
}
623633
}
624634

625635
return undefined;

0 commit comments

Comments
 (0)