From 8c50263c35fabf1e2a02691358aaae496358197f Mon Sep 17 00:00:00 2001 From: Rachel Macfarlane Date: Wed, 25 Mar 2020 16:24:53 -0700 Subject: [PATCH] Show notification when writing to keychain fails, #92972 --- extensions/github-authentication/package.json | 3 ++- .../github-authentication/src/common/keychain.ts | 12 ++++++++++-- extensions/github-authentication/yarn.lock | 5 +++++ extensions/vscode-account/src/keychain.ts | 12 ++++++++++-- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/extensions/github-authentication/package.json b/extensions/github-authentication/package.json index 254516ee527..bf2d01cbe3f 100644 --- a/extensions/github-authentication/package.json +++ b/extensions/github-authentication/package.json @@ -22,7 +22,8 @@ "postinstall": "node build/postinstall.js" }, "dependencies": { - "uuid": "^3.3.3" + "uuid": "^3.3.3", + "vscode-nls": "^4.1.2" }, "devDependencies": { "@types/keytar": "^4.4.2", diff --git a/extensions/github-authentication/src/common/keychain.ts b/extensions/github-authentication/src/common/keychain.ts index c687febb442..9a3c0c662d2 100644 --- a/extensions/github-authentication/src/common/keychain.ts +++ b/extensions/github-authentication/src/common/keychain.ts @@ -6,8 +6,11 @@ // keytar depends on a native module shipped in vscode, so this is // how we load it import * as keytarType from 'keytar'; -import { env } from 'vscode'; +import * as vscode from 'vscode'; import Logger from './logger'; +import * as nls from 'vscode-nls'; + +const localize = nls.loadMessageBundle(); function getKeytar(): Keytar | undefined { try { @@ -25,7 +28,7 @@ export type Keytar = { deletePassword: typeof keytarType['deletePassword']; }; -const SERVICE_ID = `${env.uriScheme}-github.login`; +const SERVICE_ID = `${vscode.env.uriScheme}-github.login`; const ACCOUNT_ID = 'account'; export class Keychain { @@ -46,6 +49,11 @@ export class Keychain { } catch (e) { // Ignore Logger.error(`Setting token failed: ${e}`); + const troubleshooting = localize('troubleshooting', "Troubleshooting Guide"); + const result = await vscode.window.showErrorMessage(localize('keychainWriteError', "Writing login information to the keychain failed with error '{0}'.", e.message), troubleshooting); + if (result === troubleshooting) { + vscode.env.openExternal(vscode.Uri.parse('https://code.visualstudio.com/docs/editor/settings-sync#_troubleshooting-keychain-issues')); + } } } diff --git a/extensions/github-authentication/yarn.lock b/extensions/github-authentication/yarn.lock index dcab74a1fea..c1f0b96f5b5 100644 --- a/extensions/github-authentication/yarn.lock +++ b/extensions/github-authentication/yarn.lock @@ -436,6 +436,11 @@ uuid@^3.3.3: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== +vscode-nls@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/vscode-nls/-/vscode-nls-4.1.2.tgz#ca8bf8bb82a0987b32801f9fddfdd2fb9fd3c167" + integrity sha512-7bOHxPsfyuCqmP+hZXscLhiHwe7CSuFE4hyhbs22xPIhQ4jv99FcR4eBzfYYVLP356HNFpdvz63FFb/xw6T4Iw== + which-pm-runs@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/which-pm-runs/-/which-pm-runs-1.0.0.tgz#670b3afbc552e0b55df6b7780ca74615f23ad1cb" diff --git a/extensions/vscode-account/src/keychain.ts b/extensions/vscode-account/src/keychain.ts index 465a160fef7..a52de4ff64c 100644 --- a/extensions/vscode-account/src/keychain.ts +++ b/extensions/vscode-account/src/keychain.ts @@ -6,8 +6,11 @@ // keytar depends on a native module shipped in vscode, so this is // how we load it import * as keytarType from 'keytar'; -import { env } from 'vscode'; +import * as vscode from 'vscode'; import Logger from './logger'; +import * as nls from 'vscode-nls'; + +const localize = nls.loadMessageBundle(); function getKeytar(): Keytar | undefined { try { @@ -25,7 +28,7 @@ export type Keytar = { deletePassword: typeof keytarType['deletePassword']; }; -const SERVICE_ID = `${env.uriScheme}-vscode.login`; +const SERVICE_ID = `${vscode.env.uriScheme}-vscode.login`; const ACCOUNT_ID = 'account'; export class Keychain { @@ -46,6 +49,11 @@ export class Keychain { } catch (e) { // Ignore Logger.error(`Setting token failed: ${e}`); + const troubleshooting = localize('troubleshooting', "Troubleshooting Guide"); + const result = await vscode.window.showErrorMessage(localize('keychainWriteError', "Writing login information to the keychain failed with error '{0}'.", e.message), troubleshooting); + if (result === troubleshooting) { + vscode.env.openExternal(vscode.Uri.parse('https://code.visualstudio.com/docs/editor/settings-sync#_troubleshooting-keychain-issues')); + } } }