提交 fb204a36 编写于 作者: A Andre Weinand

improve error handling for socket DA

上级 4e59ab36
......@@ -189,17 +189,6 @@ export abstract class StreamDebugAdapter extends AbstractDebugAdapter {
this.contentLength = -1;
readable.on('data', (data: Buffer) => this.handleData(data));
readable.on('close', () => {
this._onError.fire(new Error('read error'));
});
readable.on('error', (error) => {
this._onError.fire(error);
});
writable.on('error', (error) => {
this._onError.fire(error);
});
}
public sendMessage(message: DebugProtocol.ProtocolMessage): void {
......@@ -261,15 +250,27 @@ export class SocketDebugAdapter extends StreamDebugAdapter {
}
startSession(): TPromise<void> {
return new TPromise<void>((c, e) => {
return new TPromise<void>((resolve, reject) => {
let connected = false;
this.socket = net.createConnection(this.port, this.host, () => {
this.connect(this.socket, <any>this.socket);
c(null);
this.connect(this.socket, this.socket);
resolve(null);
connected = true;
});
this.socket.on('error', (err: any) => {
e(err);
this.socket.on('close', () => {
if (connected) {
this._onError.fire(new Error('connection closed'));
} else {
reject(new Error('connection closed'));
}
});
this.socket.on('error', error => {
if (connected) {
this._onError.fire(error);
} else {
reject(error);
}
});
this.socket.on('close', () => this._onExit.fire(0));
});
}
......@@ -343,8 +344,23 @@ export class DebugAdapter extends StreamDebugAdapter {
c(null);
}
}).then(_ => {
this.serverProcess.on('error', (err: Error) => this._onError.fire(err));
this.serverProcess.on('exit', (code: number, signal: string) => this._onExit.fire(code));
this.serverProcess.on('error', err => {
this._onError.fire(err);
});
this.serverProcess.on('exit', (code, signal) => {
this._onExit.fire(code);
});
this.serverProcess.stdout.on('close', () => {
this._onError.fire(new Error('read error'));
});
this.serverProcess.stdout.on('error', error => {
this._onError.fire(error);
});
this.serverProcess.stdin.on('error', error => {
this._onError.fire(error);
});
if (this.outputService) {
const sanitize = (s: string) => s.toString().replace(/\r?\n$/mg, '');
......@@ -357,7 +373,7 @@ export class DebugAdapter extends StreamDebugAdapter {
}
this.connect(this.serverProcess.stdout, this.serverProcess.stdin);
}, err => {
}, (err: Error) => {
this._onError.fire(err);
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册