diff --git a/extensions/php/src/features/validationProvider.ts b/extensions/php/src/features/validationProvider.ts index da835f7ce3c87b3bfd6ea42ccf628170db8f388f..84da3fef222100aa5560f1545658913b975bf930 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