diff --git a/binary/src/messenger.ts b/binary/src/messenger.ts index f8f02a7f9..1e2d3a745 100644 --- a/binary/src/messenger.ts +++ b/binary/src/messenger.ts @@ -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)); }