From c93167fec5d5d47a8e0342488972f20adc127580 Mon Sep 17 00:00:00 2001 From: Dirk Baeumer Date: Fri, 19 Feb 2016 12:27:08 +0100 Subject: [PATCH] Fixes #2930: Bad argument --- .../php/src/features/validationProvider.ts | 68 +++++++++++-------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/extensions/php/src/features/validationProvider.ts b/extensions/php/src/features/validationProvider.ts index da835f7ce3c..84da3fef222 100644 --- a/extensions/php/src/features/validationProvider.ts +++ b/extensions/php/src/features/validationProvider.ts @@ -184,41 +184,49 @@ export default class PHPValidationProvider { } else { args = PHPValidationProvider.BufferArgs; } - let childProcess = cp.spawn(executable, args, options); - childProcess.on('error', (error: Error) => { - if (this.executableNotFound) { + try { + let childProcess = cp.spawn(executable, args, options); + childProcess.on('error', (error: Error) => { + if (this.executableNotFound) { + resolve(); + return; + } + this.showError(error, executable); + this.executableNotFound = true; resolve(); - return; - } - let message: string = null; - if ((error).code === 'ENOENT') { - message = `Cannot validate the php file. The php program was not found. Use the 'php.validate.executablePath' setting to configure the location of 'php'`; - } else { - message = error.message ? error.message : `Failed to run php using path: ${executable}. Reason is unknown.`; - } - vscode.window.showInformationMessage(message); - this.executableNotFound = true; - resolve(); - }); - if (childProcess.pid) { - if (this.trigger === RunTrigger.onType) { - childProcess.stdin.write(textDocument.getText()); - childProcess.stdin.end(); - } - childProcess.stdout.on('data', (data: Buffer) => { - decoder.write(data).forEach(processLine); }); - childProcess.stdout.on('end', () => { - let line = decoder.end(); - if (line) { - processLine(line); + if (childProcess.pid) { + if (this.trigger === RunTrigger.onType) { + childProcess.stdin.write(textDocument.getText()); + childProcess.stdin.end(); } - this.diagnosticCollection.set(textDocument.uri, diagnostics); + childProcess.stdout.on('data', (data: Buffer) => { + decoder.write(data).forEach(processLine); + }); + childProcess.stdout.on('end', () => { + let line = decoder.end(); + if (line) { + processLine(line); + } + this.diagnosticCollection.set(textDocument.uri, diagnostics); + resolve(); + }); + } else { resolve(); - }); - } else { - resolve(); + } + } catch (error) { + this.showError(error, executable); } }); } + + private showError(error: any, executable: string): void { + let message: string = null; + if (error.code === 'ENOENT') { + message = `Cannot validate the php file. The php program was not found. Use the 'php.validate.executablePath' setting to configure the location of 'php'`; + } else { + message = error.message ? error.message : `Failed to run php using path: ${executable}. Reason is unknown.`; + } + vscode.window.showInformationMessage(message); + } } \ No newline at end of file -- GitLab