feat: detect unsupported GitLab version when adding token
Description
When adding an account using PAT, we first check if the token has required scopes !1053 (merged)
However, the token check API endpoint was introduced in 16.1 (which is why we have a minimum version requirement for 16.1).
When the user tries to add a token for an older instance, they'll see a "cryptical" error like Can't add GitLab account for https://gitlab.myinstance.xxx. Check your instance URL and network connection.
Example error log
2024-02-14T13:35:58:654 [error]: {
"userMessage": "Request failed: Can't add GitLab account for https://gitlab.myinstance.xxx. Check your instance URL and network connection.",
"errorMessage": "Fetching resource from https://gitlab.myinstance.xxx/api/v4/personal_access_tokens/self failed",
"stack": [
"Error: Fetching resource from https://gitlab.myinstance.xxx/api/v4/personal_access_tokens/self failed",
"\tat Mf (/Users/User/.vscode/extensions/gitlab.gitlab-workflow-4.0.0/extension.js:510:213)",
"\tat process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
"\tat async t.fetch (/Users/User/.vscode/extensions/gitlab.gitlab-workflow-4.0.0/extension.js:510:1632)",
"\tat async M3 (/Users/User/.vscode/extensions/gitlab.gitlab-workflow-4.0.0/extension.js:563:3609)",
"\tat async VX (/Users/User/.vscode/extensions/gitlab.gitlab-workflow-4.0.0/extension.js:563:4521)",
"\tat async /Users/User/.vscode/extensions/gitlab.gitlab-workflow-4.0.0/extension.js:765:1798",
"\tat async s.h (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:150:175235)"
],
"details": {
"message": "Fetching resource from https://gitlab.myinstance.xxx/api/v4/personal_access_tokens/self failed",
"stack": [
"Error: Fetching resource from https://gitlab.myinstance.xxx/api/v4/personal_access_tokens/self failed",
"\tat Mf (/Users/User/.vscode/extensions/gitlab.gitlab-workflow-4.0.0/extension.js:510:213)",
"\tat process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
"\tat async t.fetch (/Users/User/.vscode/extensions/gitlab.gitlab-workflow-4.0.0/extension.js:510:1632)",
"\tat async M3 (/Users/User/.vscode/extensions/gitlab.gitlab-workflow-4.0.0/extension.js:563:3609)",
"\tat async VX (/Users/User/.vscode/extensions/gitlab.gitlab-workflow-4.0.0/extension.js:563:4521)",
"\tat async /Users/User/.vscode/extensions/gitlab.gitlab-workflow-4.0.0/extension.js:765:1798",
"\tat async s.h (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:150:175235)"
],
"response": {
"status": 404,
"headers": {},
"body": "{\"error\":\"404 Not Found\"}"
}
}
}
which is expected since the GitLab instance doesn't have the endpoint, but it doesn't help the user in finding out what's happening.
Related Issues
Resolves #824 (closed)
How has this been tested?
- Change the minimum version constant to
17.0.0
- Try to add a valid pat token
(see the video from above)
Edited by Tomas Vik