Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise(async (resolve: () => void, reject: (error: Error) => void): Promise => {
const start: number = Date.now();
while (Date.now() < start + timeoutMs) {
try {
await this.checkTunnelStatus();
resolve();
return;
} catch (error) {
if (!(error instanceof RetryableTunnelStatusError)) {
reject(new Error(localize('tunnelFailed', 'Unable to establish connection to application: {0}', parseError(error).message)));
return;
} // else allow retry
}
await delay(pollingIntervalMs);
}
reject(new Error(localize('tunnelTimedOut', 'Unable to establish connection to application: Timed out')));
});
}
callWithTelemetryAndErrorHandlingSync(languageServerErrorTelemId, (context: IActionContext) => {
// tslint:disable-next-line: strict-boolean-expressions
context.telemetry.properties.jsonrpcMessage = message ? message.jsonrpc : "";
context.telemetry.measurements.secondsSinceStart = (Date.now() - this._serverStartTime) / 1000;
throw new Error(`An error occurred in the ${languageServerName}.${os.EOL}${os.EOL}${parseError(error).message}`);
});
private async checkTunnelStatus(): Promise {
const password: string = nonNullProp(this._publishCredential, 'publishingPassword');
const url: string = `https://${this._client.kuduHostName}/AppServiceTunnel/Tunnel.ashx?GetStatus&GetStatusAPIVer=2`;
const request: requestUtils.Request = await requestUtils.getDefaultRequest(url, new BasicAuthenticationCredentials(this._publishCredential.publishingUserName, password));
let tunnelStatus: ITunnelStatus;
try {
const responseBody: string = await requestUtils.sendRequest(request);
ext.outputChannel.appendLog(`[Tunnel] Checking status, body: ${responseBody}`);
// tslint:disable-next-line:no-unsafe-any
tunnelStatus = JSON.parse(responseBody);
} catch (error) {
const parsedError: IParsedError = parseError(error);
ext.outputChannel.appendLog(`[Tunnel] Checking status, error: ${parsedError.message}`);
throw new Error(localize('tunnelStatusError', 'Error getting tunnel status: {0}', parsedError.errorType));
}
if (tunnelStatus.state === AppState.STARTED) {
if ((tunnelStatus.port === 2222 && !this._isSsh) || (tunnelStatus.port !== 2222 && this._isSsh)) {
// Tunnel is pointed to default SSH port and still needs time to restart
throw new RetryableTunnelStatusError();
} else if (tunnelStatus.canReachPort) {
return;
} else {
throw new Error(localize('tunnelUnreachable', 'App is started, but port is unreachable'));
}
} else if (tunnelStatus.state === AppState.STARTING) {
throw new RetryableTunnelStatusError();
} else if (tunnelStatus.state === AppState.STOPPED) {
if (databaseInConnectionString && !this.root.isEmulator) { // emulator violates the connection string format
// If the database is in the connection string, that's all we connect to (we might not even have permissions to list databases)
databases = [{
name: databaseInConnectionString,
empty: false
}];
} else {
// https://mongodb.github.io/node-mongodb-native/3.1/api/index.html
let result: { databases: IDatabaseInfo[] } = await mongoClient.db(testDb).admin().listDatabases();
databases = result.databases;
}
return databases
.filter((database: IDatabaseInfo) => !(database.name && database.name.toLowerCase() === "admin" && database.empty)) // Filter out the 'admin' database if it's empty
.map(database => new MongoDatabaseTreeItem(this, database.name, this.connectionString));
} catch (error) {
let message = parseError(error).message;
if (this._root.isEmulator && message.includes("ECONNREFUSED")) {
error.message = `Unable to reach emulator. See ${Links.LocalConnectionDebuggingTips} for debugging tips.\n${message}`;
}
throw error;
}
finally {
if (mongoClient) {
mongoClient.close();
}
}
}
export async function uninstallDotnet(): Promise {
initializeDotnetAcquire();
ext.outputChannel.show();
ext.outputChannel.appendLine("Removing local installation of dotnet core...");
try {
await acquisitionWorker.uninstallAll();
} catch (error) {
let message = parseError(error).message;
if (message.includes('EPERM')) {
error = new Error(`Dotnet core may be in use. Please close all deployment template files, then restart VS Code and try again. ${message}`);
}
throw error;
}
ext.outputChannel.appendLine("Done. Please restart VS Code.");
}
private logError(eventName: string, error: unknown): void {
const errorData: IParsedError = parseError(error);
let properties: TelemetryProperties = {};
if (errorData.isUserCancelledError) {
properties.result = 'Canceled';
} else {
properties.result = 'Failed';
properties.error = errorData.errorType;
properties.errorMessage = errorData.message;
}
ext.reporter.sendTelemetryEvent(eventName, properties);
}
}).on('error', (err: Error) => {
if (timerId) {
clearInterval(timerId);
}
newLogStream.isConnected = false;
outputChannel.show();
outputChannel.appendLine(localize('logStreamError', 'Error connecting to log-streaming service:'));
outputChannel.appendLine(parseError(err).message);
reject(err);
}).on('complete', () => {
newLogStream.dispose();
public setResult(result: Result, error?: Error): void {
this.actionContext.telemetry.properties.result = result;
if (error) {
let parsedError = parseError(error);
this.actionContext.telemetry.properties.error = JSON.stringify(parsedError);
this.actionContext.telemetry.properties.errorMessage = parsedError.message;
}
}
public async showGraphViewer(
tabTitle: string,
config: GraphConfiguration
): Promise {
let id: number;
try {
id = await this.getOrCreateServer(config);
} catch (err) {
vscode.window.showErrorMessage(parseError(err).message);
}
let existingPanel: vscode.WebviewPanel = this._panels.get(id);
if (existingPanel) {
existingPanel.reveal();
return;
}
const column = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined;
const options: vscode.WebviewOptions & vscode.WebviewPanelOptions = {
enableScripts: true,
enableCommandUris: true,
enableFindWidget: true,
retainContextWhenHidden: true,
localResourceRoots: [vscode.Uri.file(ext.context.extensionPath)]
};
const panel = vscode.window.createWebviewPanel(this._panelViewType, tabTitle, { viewColumn: column, preserveFocus: true }, options);
let contentProvider = new WebviewContentProvider(this);