From f7f59068d516b0e45fceddddbb50302204733c8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 13 Feb 2024 09:23:43 +0100 Subject: [PATCH 1/2] refactor: rename `logs.push()` to `logs.pushLine()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make it clear in code storing logs that chunks must be split at newlines. My intention is to prevent regressions like the one fixed by #1319. Signed-off-by: Miroslav Bajtoš --- main/core.js | 8 ++++---- main/logs.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/main/core.js b/main/core.js index 26b69df86..f70feb0c9 100644 --- a/main/core.js +++ b/main/core.js @@ -39,7 +39,7 @@ async function setup (ctx) { ctx.showUI() const { filePath } = await dialog.showSaveDialog(opts) if (filePath) { - await fs.writeFile(filePath, logs.get()) + await fs.writeFile(filePath, logs.getLines()) } } await maybeMigrateFiles() @@ -68,7 +68,7 @@ async function start (ctx) { childProcess.stdout .pipe(split2()) .on('data', line => { - logs.push(line) + logs.pushLine(line) let event try { event = JSON.parse(line) @@ -115,7 +115,7 @@ async function start (ctx) { childProcess.stderr.setEncoding('utf8') childProcess.stderr .pipe(split2()) - .on('data', line => logs.push(line)) + .on('data', line => logs.pushLine(line)) /** @type {string | null} */ let exitReason = null @@ -129,7 +129,7 @@ async function start (ctx) { Sentry.captureException('Core exited', scope => { // Sentry UI can't show the full 100 lines - scope.setExtra('logs', logs.getLast(10)) + scope.setExtra('logs', logs.getLastLines(10)) scope.setExtra('reason', exitReason) return scope }) diff --git a/main/logs.js b/main/logs.js index 1e9ef081a..5dae33d0f 100644 --- a/main/logs.js +++ b/main/logs.js @@ -8,20 +8,20 @@ class Logs { * Keep last 100 lines of logs for inspection * @param {string} line */ - push (line) { + pushLine (line) { this.#logs.push(line) this.#logs.splice(0, this.#logs.length - 100) } - get () { - return this.getLast(Infinity) + getLines () { + return this.getLastLines(Infinity) } /** * @param {number} n * @returns string */ - getLast (n) { + getLastLines (n) { return this.#logs.slice(-n).join('\n') } } From 09efdc117b390931a57a5ee072243e50f23c4cd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 13 Feb 2024 13:52:42 +0100 Subject: [PATCH 2/2] fixup! keep `logs.get()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miroslav Bajtoš --- main/core.js | 2 +- main/logs.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/core.js b/main/core.js index f70feb0c9..7b4a9cd96 100644 --- a/main/core.js +++ b/main/core.js @@ -39,7 +39,7 @@ async function setup (ctx) { ctx.showUI() const { filePath } = await dialog.showSaveDialog(opts) if (filePath) { - await fs.writeFile(filePath, logs.getLines()) + await fs.writeFile(filePath, logs.get()) } } await maybeMigrateFiles() diff --git a/main/logs.js b/main/logs.js index 5dae33d0f..9c3173ee2 100644 --- a/main/logs.js +++ b/main/logs.js @@ -13,7 +13,7 @@ class Logs { this.#logs.splice(0, this.#logs.length - 100) } - getLines () { + get () { return this.getLastLines(Infinity) }