Skip to content

Commit 2087bd3

Browse files
committed
gracefully handle JSON.parse errors
1 parent faca4d3 commit 2087bd3

File tree

1 file changed

+10
-2
lines changed
  • packages/vscode-ws-jsonrpc/src/socket

1 file changed

+10
-2
lines changed

packages/vscode-ws-jsonrpc/src/socket/reader.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,16 @@ export class WebSocketMessageReader extends AbstractMessageReader implements Mes
6060
if (this.state === 'initial') {
6161
this.events.splice(0, 0, { message });
6262
} else if (this.state === 'listening') {
63-
const data = JSON.parse(message);
64-
this.callback!(data);
63+
try {
64+
const data = JSON.parse(message);
65+
this.callback!(data);
66+
} catch (err) {
67+
const error: Error = {
68+
name: '' + 400,
69+
message: `Error during message parsing, reason = ${typeof err === 'object' ? (err as any).message : 'unknown'}`
70+
};
71+
this.fireError(error);
72+
}
6573
}
6674
}
6775

0 commit comments

Comments
 (0)