Skip to content

Commit 18eaee5

Browse files
authored
fix: show different dialogs for authorization errors and other errors (#305)
This PR adds a new command `loginFailedNudge` which is different from the `loginNudge`. This command is intended to be the pop up dialog for any non-authorization errors occurred during login. Reasons as to why we need to do this is documented here: semgrep/semgrep-proprietary#5938 This change should only be released after the change in the `semgrep-proprietary` repo is released and bumped in this repo. ## Test plan: ### Experimental LS No token: <img width="351" height="250" alt="image" src="https://github.com/user-attachments/assets/80c27218-c8f9-4f73-a00e-d46b421275cb" /> Network error: <img width="351" height="250" alt="image" src="https://app.graphite.com/user-attachments/assets/aab1c8e2-1689-47f6-8fce-82cd45119838.png" /> and token was not cleared out. Bad token (authorization error): <img width="354" height="193" alt="image" src="https://github.com/user-attachments/assets/5d9e7eea-3c5e-4c0b-9664-739ca438ed6f" /> and token was not cleared out. Also checked that rules were successfully refreshed for the valid token case ### Legacy: No token: <img width="347" height="248" alt="image" src="https://github.com/user-attachments/assets/d6ad590d-9902-420b-9552-c4aa264dc9e8" /> Network error: <img width="357" height="282" alt="image" src="https://github.com/user-attachments/assets/0223c81e-4aa3-4f66-bd6a-a46446e34db6" /> and token wasn't cleared out. Bad token (authorization error): <img width="355" height="196" alt="image" src="https://github.com/user-attachments/assets/2a290e84-a729-4cf3-ab60-f669a9382cdb" /> and token wasn't cleared out. Also checked that rules were successfully refreshed for the valid token case PR checklist: - [x] Purpose of the code is [evident to future readers](https://semgrep.dev/docs/contributing/contributing-code/#explaining-code) - [x] Tests included or PR comment includes a reproducible test plan - [x] Documentation is up-to-date - [x] A changelog entry was for any user-facing change - [x] Change has no security implications (otherwise, ping security team) If you're unsure about any of this, please see: - [Contribution guidelines](https://semgrep.dev/docs/contributing/contributing-code)! - [One of the more specific guides located here](https://semgrep.dev/docs/contributing/contributing/)
1 parent 1f185f9 commit 18eaee5

3 files changed

Lines changed: 44 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## Fixed
11+
12+
- Startup login verification: unrelated LSP failures are no longer misreported as auth errors; users get a notification with reload, sign in again, or dismiss.
13+
1014
## 1.16.0 - 2025-09-23
1115

1216
## Fixed

src/commands.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ export function registerCommands(env: Environment): Disposable[] {
7979
}
8080
}),
8181

82+
vscode.commands.registerCommand("semgrep.loginFailedNudge", async () => {
83+
const resp = await vscode.window.showInformationMessage(
84+
"Semgrep could not connect to verify your login status. This doesn't mean your login status is invalid, but it may mean you need to try again.",
85+
"Reload Window",
86+
"Login",
87+
"Dismiss",
88+
);
89+
if (resp === "Reload Window") {
90+
vscode.commands.executeCommand("workbench.action.reloadWindow");
91+
} else if (resp === "Login") {
92+
vscode.commands.executeCommand("semgrep.login");
93+
}
94+
}),
95+
8296
vscode.commands.registerCommand("semgrep.mcpSetup", async () => {
8397
const repoPath = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath;
8498
if (

src/extension.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,35 @@ async function afterClientStart(context: ExtensionContext, env: Environment) {
7979
},
8080
),
8181
);
82-
vscode.commands.executeCommand("semgrep.loginStatus").then(async () => {
83-
vscode.commands.executeCommand("semgrep.loginNudge");
84-
if (env.newInstall) {
85-
env.newInstall = false;
82+
vscode.commands
83+
.executeCommand("semgrep.loginStatus")
84+
.then(
85+
async () => {
86+
vscode.commands.executeCommand("semgrep.loginNudge");
87+
},
88+
() => {
89+
vscode.commands.executeCommand("semgrep.loginFailedNudge");
90+
},
91+
)
92+
.then(async () => {
93+
if (env.newInstall) {
94+
env.newInstall = false;
8695

87-
await vscode.window.showInformationMessage(
88-
`VS Code collects usage data and sends it to Semgrep to help improve our products and services. Telemetry data includes extension runtime version details, and other metrics normally collected by Semgrep, [as described here](https://semgrep.dev/docs/metrics#data-collected-as-metrics).
96+
await vscode.window.showInformationMessage(
97+
`VS Code collects usage data and sends it to Semgrep to help improve our products and services. Telemetry data includes extension runtime version details, and other metrics normally collected by Semgrep, [as described here](https://semgrep.dev/docs/metrics#data-collected-as-metrics).
8998
If you don't wish to send usage data to Semgrep, you can unset the \`Semgrep: Metrics\` setting.`,
90-
);
91-
92-
const selection = await vscode.window.showInformationMessage(
93-
"Semgrep Extension successfully installed. Would you like to try performing a full workspace scan (may take longer on bigger workspaces)?",
94-
"Scan Full Workspace",
95-
"Dismiss",
96-
);
97-
if (selection == "Scan Full Workspace") {
98-
vscode.commands.executeCommand("semgrep.scanWorkspaceFull");
99+
);
100+
101+
const selection = await vscode.window.showInformationMessage(
102+
"Semgrep Extension successfully installed. Would you like to try performing a full workspace scan (may take longer on bigger workspaces)?",
103+
"Scan Full Workspace",
104+
"Dismiss",
105+
);
106+
if (selection == "Scan Full Workspace") {
107+
vscode.commands.executeCommand("semgrep.scanWorkspaceFull");
108+
}
99109
}
100-
}
101-
});
110+
});
102111
vscode.commands.executeCommand("semgrep.mcpSetup");
103112
}
104113

0 commit comments

Comments
 (0)