🐛 handle messages sent in multiple parts over stdin
This commit is contained in:
parent
e9afe48db6
commit
befba0e56a
1 changed files with 19 additions and 2 deletions
|
|
@ -80,14 +80,31 @@ export class IpcMessenger {
|
|||
// Call handler which is waiting for the response, nothing to return
|
||||
this.idListeners.get(msg.messageId)?.(msg);
|
||||
} catch (e) {
|
||||
console.error("Error parsing line: ", line, e);
|
||||
let truncatedLine = line;
|
||||
if (line.length > 200) {
|
||||
truncatedLine =
|
||||
line.substring(0, 100) + "..." + line.substring(line.length - 100);
|
||||
}
|
||||
console.error("Error parsing line: ", truncatedLine, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private _unfinishedLine: string | undefined = undefined;
|
||||
private _handleData(data: Buffer) {
|
||||
const d = data.toString();
|
||||
const lines = d.split(/\r\n|\r|\n/).filter((line) => line.trim() !== "");
|
||||
const lines = d.split(/\r\n/).filter((line) => line.trim() !== "");
|
||||
if (lines.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._unfinishedLine) {
|
||||
lines[0] = this._unfinishedLine + lines[0];
|
||||
this._unfinishedLine = undefined;
|
||||
}
|
||||
if (!d.endsWith("\r\n")) {
|
||||
this._unfinishedLine = lines.pop();
|
||||
}
|
||||
lines.forEach((line) => this._handleLine(line));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue