Skip to content

Commit

Permalink
refactor: rename logs.push() to logs.pushLine()
Browse files Browse the repository at this point in the history
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š <oss@bajtos.net>
  • Loading branch information
bajtos committed Feb 13, 2024
1 parent e924e5a commit f7f5906
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions main/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
})
Expand Down
8 changes: 4 additions & 4 deletions main/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}
Expand Down

0 comments on commit f7f5906

Please sign in to comment.