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..6e8c163629 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' @@ -30,37 +30,48 @@ export class LogTableWebview { private setupIncomingListeners(): void { 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) => { - if (url !== 'requesting') { - await accessLog(url, this.logData.logs[itemNumber].runId, message.logRequest.download); - } + await callWithTelemetryAndErrorHandling( + 'ACRLogs-accessLogs', + async () => { + + const itemNumber: number = +message.logRequest.id; + 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); - + await callWithTelemetryAndErrorHandling( + 'ACRLogs-copyDigest', + async () => { + // 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({ - webViewEvent: true, - loadNext: true - }); - this.addLogsToWebView(alreadyLoaded); - + await callWithTelemetryAndErrorHandling( + 'ACRLogs-loadMore', + async () => { + const alreadyLoaded = this.logData.logs.length; + await this.logData.loadLogs({ + webViewEvent: true, + loadNext: true + }); + this.addLogsToWebView(alreadyLoaded); + }); } else if (message.loadFiltered) { - await this.logData.loadLogs({ - webViewEvent: true, - loadNext: false, - removeOld: true, - filter: message.loadFiltered.filterString - }); - this.addLogsToWebView(); + await callWithTelemetryAndErrorHandling( + 'ACRLogs-filterTable', + async () => { + await this.logData.loadLogs({ + webViewEvent: true, + loadNext: false, + removeOld: true, + filter: message.loadFiltered.filterString + }); + this.addLogsToWebView(); + }); } }); } 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; diff --git a/commands/utils/SourceArchiveUtility.ts b/commands/utils/SourceArchiveUtility.ts index 7523aa1985..c9aa60d203 100644 --- a/commands/utils/SourceArchiveUtility.ts +++ b/commands/utils/SourceArchiveUtility.ts @@ -98,7 +98,15 @@ async function uploadSourceCode(client: ContainerRegistryManagementClient, regis ext.outputChannel.appendLine(" Creating blob service "); let blob: BlobService = createBlobServiceWithSas(blobInfo.host, blobInfo.sasToken); ext.outputChannel.appendLine(" Creating block blob "); - blob.createBlockBlobFromLocalFile(blobInfo.containerName, blobInfo.blobName, tarFilePath, (): void => { }); + await new Promise((resolve, reject) => { + blob.createBlockBlobFromLocalFile(blobInfo.containerName, blobInfo.blobName, tarFilePath, (error, result, response): void => { + if (error) { + reject(error); + } else { + resolve({ result, response }); + } + }); + }); return relative_path; } diff --git a/dockerExtension.ts b/dockerExtension.ts index c367f60ec9..19a2079eb0 100644 --- a/dockerExtension.ts +++ b/dockerExtension.ts @@ -10,7 +10,7 @@ import { CoreOptions } from 'request'; import * as request from 'request-promise-native'; import { RequestPromise } from 'request-promise-native'; import * as vscode from 'vscode'; -import { AzureUserInput, callWithTelemetryAndErrorHandling, callWithTelemetryAndErrorHandlingSync, createTelemetryReporter, IActionContext, registerCommand as uiRegisterCommand, registerUIExtensionVariables, TelemetryProperties, UserCancelledError } from 'vscode-azureextensionui'; +import { AzureUserInput, callWithTelemetryAndErrorHandling, createTelemetryReporter, IActionContext, registerCommand as uiRegisterCommand, registerUIExtensionVariables, TelemetryProperties, UserCancelledError } from 'vscode-azureextensionui'; import { ConfigurationParams, DidChangeConfigurationNotification, DocumentSelector, LanguageClient, LanguageClientOptions, Middleware, ServerOptions, TransportKind } from 'vscode-languageclient/lib/main'; import { viewACRLogs } from "./commands/azureCommands/acr-logs"; import { LogContentProvider } from "./commands/azureCommands/acr-logs-utils/logFileManager";