[VS Code] Invalid OAuth token is not surfaced as a notification to the user
Checklist
-
I'm using the latest version of the extension (see the latest version in the right column of this page) - Extension version: 3.95.0
-
I'm using the latest VS Code version (find the latest version here) - VS Code version: 1.85.1
-
I'm using a supported version of GitLab (see README for the supported version) - GitLab version:
gitlab.com
- GitLab version:
Summary
When using Code Suggestions streaming with an invalid OAuth token, Code Suggestions do not work (expected), which is not surfaced to the user except in the logs.
Steps to reproduce
- Enable streaming
- Find an instance of VS Code that has an expired OAuth token
- Trigger streaming by writing a long comment
What is the current bug behavior?
- No visible feedback (e.g. pop-up notification) that the token is invalid
- Language Server logs show
invalid_token
error (see below)
What is the expected correct behavior?
- Visible feedback with an action to re-authenticate
Relevant logs and/or screenshots
2023-12-20T15:41:36:669 [info]: GitLab Language Server is starting
2023-12-20T15:41:36:846 [info]: GitLab Language Server has started
2023-12-20T15:41:36:860 [info]: Checking token for OAuth validity
2023-12-20T15:41:36:949 [info]: Checking token for OAuth validity
2023-12-20T15:41:36:995 [info]: Checking token for OAuth validity
2023-12-20T15:41:37:147 [debug]: fetch: request to https://gitlab.com/oauth/token/info returned HTTP 401 after 286 ms
2023-12-20T15:41:37:148 [error]: Error performing token check
Unauthorized
Error: Unauthorized
at #n (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:121:1177)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WB.checkToken (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:121:1354)
at async Tu.didChangeConfigurationHandler (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:127:1450)
2023-12-20T15:41:37:148 [warning]: Token is invalid. Failed to check token: Error: Unauthorized. Reason: unknown
2023-12-20T15:41:37:219 [debug]: fetch: request to https://gitlab.com/oauth/token/info returned HTTP 401 after 269 ms
2023-12-20T15:41:37:219 [error]: Error performing token check
Unauthorized
Error: Unauthorized
at #n (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:121:1177)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WB.checkToken (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:121:1354)
at async Tu.didChangeConfigurationHandler (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:127:1450)
2023-12-20T15:41:37:219 [warning]: Token is invalid. Failed to check token: Error: Unauthorized. Reason: unknown
2023-12-20T15:41:37:267 [debug]: fetch: request to https://gitlab.com/oauth/token/info returned HTTP 401 after 272 ms
2023-12-20T15:41:37:267 [error]: Error performing token check
Unauthorized
Error: Unauthorized
at #n (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:121:1177)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WB.checkToken (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:121:1354)
at async Tu.didChangeConfigurationHandler (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:127:1450)
2023-12-20T15:41:37:267 [warning]: Token is invalid. Failed to check token: Error: Unauthorized. Reason: unknown
2023-12-20T15:54:10:355 [info]: Checking token for OAuth validity
2023-12-20T15:54:10:638 [debug]: fetch: request to https://gitlab.com/oauth/token/info returned HTTP 401 after 282 ms
2023-12-20T15:54:10:638 [error]: Error performing token check
Unauthorized
Error: Unauthorized
at #n (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:121:1177)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WB.checkToken (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:121:1354)
at async Tu.didChangeConfigurationHandler (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:127:1450)
2023-12-20T15:54:10:638 [warning]: Token is invalid. Failed to check token: Error: Unauthorized. Reason: unknown
2023-12-20T16:11:39:859 [debug]: DesktopTreeSitterParser: Initialized tree-sitter parser.
2023-12-20T16:11:39:863 [debug]: TreeSitterParser: Loaded tree-sitter grammar (tree-sitter-ruby.wasm present).
2023-12-20T16:11:39:867 [debug]: TreeSitterParser: Detected intent generation using tree-sitter with context.
2023-12-20T16:11:39:983 [debug]: TreeSitterParser: Detected intent generation using tree-sitter with context.
2023-12-20T16:11:40:169 [debug]: debounce triggered for streaming
2023-12-20T16:11:40:545 [error]: Error streaming code suggestions.
Error in calling GitLab HTTP error! Status: 401, Body = {"error":"invalid_token","error_description":"Token is expired. You can either do re-authorization or token refresh."}
Error: Error in calling GitLab HTTP error! Status: 401, Body = {"error":"invalid_token","error_description":"Token is expired. You can either do re-authorization or token refresh."}
at at (/Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:120:79)
at /Users/fvarose/.vscode/extensions/gitlab.gitlab-workflow-3.95.0/assets/language-server/node/main-bundle.js:127:7240
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Possible fixes
Potentially same fix as identified in #1131 (comment 1675163969).
additional details
@viktomas made the LS notification into a logged warning instead of user-facing notification https://gitlab.com/gitlab-org/gitlab-vscode-extension/blob/14e29c5f1b77d19cde09d0a18e08c3f7418a4327/src/common/language_server/language_client_wrapper.ts#L49, that's because during the extension startup, it was possible to get false positive (notification about expired token) because the extension first starts LS (with expired token) and only then refreshes the token and updates LS, but by that time user already saw a false-positive error.
Fix for this issue must ensure that this false positive doesn't happen anymore. (if you start VS code with expired token, you don't see false-positive error notification from LS).