From 0b10d1a3519edb1cbdefb18c67e58fee42b75041 Mon Sep 17 00:00:00 2001 From: rosanch <43052640+rosanch@users.noreply.github.com> Date: Tue, 11 Dec 2018 17:15:26 -0800 Subject: [PATCH] Fixes the following issues : Unhandled error if you cancel saving Azure log #639 Save Azure log dialog shows "log..log" as the filename extension #640 docker.acr.pullimage issue #648 --- .../acr-logs-utils/logFileManager.ts | 9 ++++++++- .../acr-logs-utils/tableViewManager.ts | 16 +++++++--------- commands/azureCommands/pull-from-azure.ts | 7 +++---- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/commands/azureCommands/acr-logs-utils/logFileManager.ts b/commands/azureCommands/acr-logs-utils/logFileManager.ts index 93bb31810f..07147b0e4e 100644 --- a/commands/azureCommands/acr-logs-utils/logFileManager.ts +++ b/commands/azureCommands/acr-logs-utils/logFileManager.ts @@ -1,6 +1,8 @@ import { BlobService, createBlobServiceWithSas } from 'azure-storage'; import * as fse from 'fs-extra'; +import { isNullOrUndefined } from 'util'; import * as vscode from 'vscode'; +import { UserCancelledError } from 'vscode-azureextensionui'; import { getBlobInfo, getBlobToText, IBlobInfo } from '../../../utils/Azure/acrTools'; export class LogContentProvider implements vscode.TextDocumentContentProvider { @@ -55,9 +57,14 @@ function openLogInNewWindow(content: string, title: string): void { export async function downloadLog(content: string, title: string): Promise { let uri = await vscode.window.showSaveDialog({ - filters: { 'Log': ['.log', '.txt'] }, + filters: { 'Log': ['log', 'txt'] }, defaultUri: vscode.Uri.file(`${title}.log`) }); + + if (isNullOrUndefined(uri)) { + throw new UserCancelledError("Operation cancelled."); + } + fse.writeFile( uri.fsPath, content, diff --git a/commands/azureCommands/acr-logs-utils/tableViewManager.ts b/commands/azureCommands/acr-logs-utils/tableViewManager.ts index 94ee74c34f..5eddcd1a3e 100644 --- a/commands/azureCommands/acr-logs-utils/tableViewManager.ts +++ b/commands/azureCommands/acr-logs-utils/tableViewManager.ts @@ -3,7 +3,7 @@ import { ImageDescriptor, Run } from "azure-arm-containerregistry/lib/models"; import * as clipboardy from 'clipboardy' import * as path from 'path'; import * as vscode from "vscode"; -import { parseError } from "vscode-azureextensionui"; +import { callWithTelemetryAndErrorHandling } from "vscode-azureextensionui"; import { ext } from "../../../extensionVariables"; import { accessLog } from './logFileManager'; import { Filter, LogData } from './tableDataManager' @@ -31,20 +31,18 @@ export class LogTableWebview { this.panel.webview.onDidReceiveMessage(async (message: IMessage) => { if (message.logRequest) { const itemNumber: number = +message.logRequest.id; - try { - await this.logData.getLink(itemNumber).then(async (url) => { + await callWithTelemetryAndErrorHandling( + 'accessLogFromTable', + async () => await this.logData.getLink(itemNumber).then(async (url) => { if (url !== 'requesting') { await accessLog(url, this.logData.logs[itemNumber].runId, message.logRequest.download); } - }); - } catch (err) { - const error = parseError(err); - vscode.window.showErrorMessage(`Error '${error.errorType}': ${error.message}`); - } + }) + ); } else if (message.copyRequest) { // tslint:disable-next-line:no-unsafe-any clipboardy.writeSync(message.copyRequest.text); - + vscode.window.showInformationMessage("The digest was successfully copied to the clipboard."); } else if (message.loadMore) { const alreadyLoaded = this.logData.logs.length; await this.logData.loadLogs({ diff --git a/commands/azureCommands/pull-from-azure.ts b/commands/azureCommands/pull-from-azure.ts index 666c384510..0445742b42 100644 --- a/commands/azureCommands/pull-from-azure.ts +++ b/commands/azureCommands/pull-from-azure.ts @@ -7,6 +7,7 @@ import * as assert from 'assert'; import { Registry } from "azure-arm-containerregistry/lib/models"; import { exec } from 'child_process'; import * as fse from 'fs-extra'; +import os = require('os'); import * as path from "path"; import vscode = require('vscode'); import { callWithTelemetryAndErrorHandling, IActionContext } from 'vscode-azureextensionui'; @@ -59,8 +60,6 @@ async function pullFromAzure(context: AzureImageTagNode | AzureRepositoryNode, p async function pullImage(loginServer: string, imageRequest: string, username: string, password: string): Promise { // We can't know if the key is still active. So we login into Docker and send appropriate commands to terminal - let dockerConfigPath: string = path.join(process.env.HOMEPATH, '.docker', 'config.json'); - await new Promise((resolve, reject) => { const dockerLoginCmd = `docker login ${loginServer} --username ${username} --password-stdin`; let childProcess = exec(dockerLoginCmd, (err, stdout, stderr) => { @@ -71,7 +70,7 @@ async function pullImage(loginServer: string, imageRequest: string, username: st // Temporary work-around for this error- same as Azure CLI // See https://github.com/Azure/azure-cli/issues/4843 ext.outputChannel.show(); - reject(new Error(`In order to log in to the Docker CLI using tokens, you currently need to go to \n${dockerConfigPath} and remove "credsStore": "wincred" from the config.json file, then try again. \nDoing this will disable wincred and cause Docker to store credentials directly in the .docker/config.json file. All registries that are currently logged in will be effectly logged out.`)); + reject(new Error(`In order to log in to the Docker CLI using tokens, you currently need to go to \nOpen your Docker config file and remove "credsStore": "wincred" from the config.json file, then try again. \nDoing this will disable wincred and cause Docker to store credentials directly in the .docker/config.json file. All registries that are currently logged in will be effectly logged out.`)); } else if (err) { ext.outputChannel.show(); reject(err); @@ -94,7 +93,7 @@ async function pullImage(loginServer: string, imageRequest: string, username: st } async function isLoggedIntoDocker(loginServer: string): Promise<{ configPath: string, loggedIn: boolean }> { - let home = process.env.HOMEPATH; + const home = os.homedir(); let configPath: string = path.join(home, '.docker', 'config.json'); let buffer: Buffer;