From 00ead383df08c70c24abf25216ef9ef7ef0782a4 Mon Sep 17 00:00:00 2001 From: Andre Weinand Date: Thu, 7 Mar 2019 17:58:01 +0100 Subject: [PATCH] use async version of fs.exists; fixes #69860 --- .../contrib/debug/node/debugAdapter.ts | 66 ++++++++++--------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/src/vs/workbench/contrib/debug/node/debugAdapter.ts b/src/vs/workbench/contrib/debug/node/debugAdapter.ts index 2f3845662d4..898c02649ec 100644 --- a/src/vs/workbench/contrib/debug/node/debugAdapter.ts +++ b/src/vs/workbench/contrib/debug/node/debugAdapter.ts @@ -310,65 +310,67 @@ export class ExecutableDebugAdapter extends StreamDebugAdapter { super(); } - startSession(): Promise { - - return new Promise((resolve, reject) => { - - // verify executables - if (this.adapterExecutable.command) { - if (path.isAbsolute(this.adapterExecutable.command)) { - if (!fs.existsSync(this.adapterExecutable.command)) { - reject(new Error(nls.localize('debugAdapterBinNotFound', "Debug adapter executable '{0}' does not exist.", this.adapterExecutable.command))); + async startSession(): Promise { + + const command = this.adapterExecutable.command; + const args = this.adapterExecutable.args; + const options = this.adapterExecutable.options || {}; + + try { + // verify executables asynchronously + if (command) { + if (path.isAbsolute(command)) { + const ok = await new Promise(resolve => fs.exists(command, resolve)); + if (!ok) { + throw new Error(nls.localize('debugAdapterBinNotFound', "Debug adapter executable '{0}' does not exist.", command)); } } else { // relative path - if (this.adapterExecutable.command.indexOf('/') < 0 && this.adapterExecutable.command.indexOf('\\') < 0) { + if (command.indexOf('/') < 0 && command.indexOf('\\') < 0) { // no separators: command looks like a runtime name like 'node' or 'mono' // TODO: check that the runtime is available on PATH } } } else { - reject(new Error(nls.localize({ key: 'debugAdapterCannotDetermineExecutable', comment: ['Adapter executable file not found'] }, - "Cannot determine executable for debug adapter '{0}'.", this.debugType))); + throw new Error(nls.localize({ key: 'debugAdapterCannotDetermineExecutable', comment: ['Adapter executable file not found'] }, + "Cannot determine executable for debug adapter '{0}'.", this.debugType)); } let env = objects.mixin({}, process.env); - if (this.adapterExecutable.options && this.adapterExecutable.options.env) { - env = objects.mixin(env, this.adapterExecutable.options.env); + if (options.env) { + env = objects.mixin(env, options.env); } delete env.VSCODE_PREVENT_FOREIGN_INSPECT; - if (this.adapterExecutable.command === 'node') { - if (Array.isArray(this.adapterExecutable.args) && this.adapterExecutable.args.length > 0) { + if (command === 'node') { + if (Array.isArray(args) && args.length > 0) { const isElectron = !!process.env['ELECTRON_RUN_AS_NODE'] || !!process.versions['electron']; - const options: cp.ForkOptions = { + const forkOptions: cp.ForkOptions = { env: env, execArgv: isElectron ? ['-e', 'delete process.env.ELECTRON_RUN_AS_NODE;require(process.argv[1])'] : [], silent: true }; - if (this.adapterExecutable.options && this.adapterExecutable.options.cwd) { - options.cwd = this.adapterExecutable.options.cwd; + if (options.cwd) { + forkOptions.cwd = options.cwd; } - const child = cp.fork(this.adapterExecutable.args[0], this.adapterExecutable.args.slice(1), options); + const child = cp.fork(args[0], args.slice(1), forkOptions); if (!child.pid) { - reject(new Error(nls.localize('unableToLaunchDebugAdapter', "Unable to launch debug adapter from '{0}'.", this.adapterExecutable.args[0]))); + throw new Error(nls.localize('unableToLaunchDebugAdapter', "Unable to launch debug adapter from '{0}'.", args[0])); } this.serverProcess = child; - resolve(); } else { - reject(new Error(nls.localize('unableToLaunchDebugAdapterNoArgs', "Unable to launch debug adapter."))); + throw new Error(nls.localize('unableToLaunchDebugAdapterNoArgs', "Unable to launch debug adapter.")); } } else { - const options: cp.SpawnOptions = { + const spawnOptions: cp.SpawnOptions = { env: env }; - if (this.adapterExecutable.options && this.adapterExecutable.options.cwd) { - options.cwd = this.adapterExecutable.options.cwd; + if (options.cwd) { + spawnOptions.cwd = options.cwd; } - this.serverProcess = cp.spawn(this.adapterExecutable.command, this.adapterExecutable.args, options); - resolve(); + this.serverProcess = cp.spawn(command, args, spawnOptions); } - }).then(_ => { + this.serverProcess.on('error', err => { this._onError.fire(err); }); @@ -401,10 +403,12 @@ export class ExecutableDebugAdapter extends StreamDebugAdapter { }); } + // finally connect to the DA this.connect(this.serverProcess.stdout, this.serverProcess.stdin); - }, (err: Error) => { + + } catch (err) { this._onError.fire(err); - }); + } } stopSession(): Promise { -- GitLab