Skip to content

Commit a023301

Browse files
committed
additional error handling
1 parent 563264b commit a023301

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ Works on both Windows and Mac.
103103

104104
## Change Log
105105

106+
### Version 0.2.8
107+
* Improved error handling in the extension
108+
106109
### Version 0.2.8
107110
* Added support for debugging django applications
108111
+ Debugging templates is not supported at this stage

src/client/common/configSettings.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface IPythonSettings {
1212
}
1313
export interface IUnitTestSettings {
1414
nosetestsEnabled: boolean;
15-
nosetestPath:string;
15+
nosetestPath: string;
1616
unittestEnabled: boolean;
1717
}
1818
export interface IPylintCategorySeverity {
@@ -51,7 +51,7 @@ export class PythonSettings implements IPythonSettings {
5151

5252
this.initializeSettings();
5353
}
54-
private getVirtualenvPath() {
54+
private getVirtualenvPath(): string {
5555
var currentPath: string = vscode.workspace.rootPath;
5656
if (process.platform == 'win32') {
5757
var bin: string = "Scripts";
@@ -63,11 +63,12 @@ export class PythonSettings implements IPythonSettings {
6363
}
6464
return fs.existsSync(_path)
6565
? _path
66-
: this.pythonPath;
66+
: null;
6767
}
6868
private initializeSettings() {
6969
var pythonSettings = vscode.workspace.getConfiguration("python");
70-
this.pythonPath = this.getVirtualenvPath()
70+
var virtualEnvPath = this.getVirtualenvPath();
71+
this.pythonPath = typeof virtualEnvPath === "string" ? virtualEnvPath : pythonSettings.get<string>("pythonPath");
7172
var lintingSettings = pythonSettings.get<ILintingSettings>("linting");
7273
if (this.linting) {
7374
Object.assign<ILintingSettings, ILintingSettings>(this.linting, lintingSettings);

src/client/providers/jediProxy.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,29 @@ function killProcess() {
162162
catch (ex) { }
163163
}
164164

165+
function handleError(source: string, errorMessage: string) {
166+
console.error(`Error (${source}) ${errorMessage}`);
167+
vscode.window.showErrorMessage(`There was an error in the python extension. Error ${errorMessage}`);
168+
}
169+
165170
function spawnProcess(dir: string) {
166171
try {
167172
proc = child_process.spawn(pythonSettings.pythonPath, ["-u", "completion.py"], {
168173
cwd: dir
169174
});
170175
}
171176
catch (ex) {
172-
var x = "";
177+
return handleError("spawnProcess", ex.message);
173178
}
174179
proc.stderr.on("data", (data) => {
175-
console.error("Error " + data);
180+
handleError("stderr", data);
176181
});
177-
178182
proc.on("end", (end) => {
179183
console.error("End - " + end);
180184
});
185+
proc.on("error", error => {
186+
handleError("error", error);
187+
});
181188

182189
proc.stdout.on("data", (data) => {
183190
var dataStr = previousData = previousData + data + ""
@@ -187,7 +194,7 @@ function spawnProcess(dir: string) {
187194
previousData = "";
188195
}
189196
catch (ex) {
190-
console.log(ex.message);
197+
handleError("stdout", ex.message);
191198
return;
192199
}
193200

@@ -309,13 +316,28 @@ function spawnProcess(dir: string) {
309316

310317
function sendCommand<T extends ICommandResult>(cmd: ICommand<T>): Promise<T> {
311318
return new Promise<ICommandResult>((resolve, reject) => {
319+
if (!proc) {
320+
return reject("Python proc not initialized");
321+
}
312322
var exexcutionCmd = <IExecutionCommand<T>>cmd;
313323
var payload = createPayload(exexcutionCmd);
314324
exexcutionCmd.resolve = resolve;
315325
exexcutionCmd.reject = reject;
316-
proc.stdin.write(JSON.stringify(payload) + "\n");
317-
commands.set(exexcutionCmd.id, exexcutionCmd);
318-
commandQueue.push(exexcutionCmd.id);
326+
try {
327+
proc.stdin.write(JSON.stringify(payload) + "\n");
328+
commands.set(exexcutionCmd.id, exexcutionCmd);
329+
commandQueue.push(exexcutionCmd.id);
330+
}
331+
catch (ex) {
332+
//If 'This socket is closed.' that means process didn't start at all (at least not properly)
333+
if (ex.message === "This socket is closed.") {
334+
killProcess();
335+
}
336+
else {
337+
handleError("sendCommand", ex.message);
338+
}
339+
reject(ex.message);
340+
}
319341
});
320342
}
321343

@@ -447,7 +469,7 @@ export class JediProxyHandler<R extends ICommandResult, T> {
447469
this.cancellationTokenSource = new vscode.CancellationTokenSource();
448470
executionCmd.token = this.cancellationTokenSource.token;
449471

450-
this.jediProxy.sendCommand<R>(executionCmd).then(data=> this.onResolved(data));
472+
this.jediProxy.sendCommand<R>(executionCmd).then(data=> this.onResolved(data), () => { });
451473
this.lastCommandId = executionCmd.id;
452474
this.lastToken = token;
453475
this.promiseResolve = resolve;

0 commit comments

Comments
 (0)