fix(desktop): suppress EPIPE errors in console transport (#25980)

This commit is contained in:
Brendan Allan 2026-05-06 15:30:18 +08:00 committed by GitHub
parent acca2e92dc
commit 754a1fb712
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,7 @@ const TAIL_LINES = 1000
export function initLogging() {
log.transports.file.maxSize = 5 * 1024 * 1024
initConsoleTransport()
cleanup()
return log
}
@ -38,3 +39,19 @@ function cleanup() {
}
}
}
function initConsoleTransport() {
const write = log.transports.console.writeFn.bind(log.transports.console)
log.transports.console.writeFn = (options) => {
try {
write(options)
} catch (err) {
if (!isBrokenPipe(err)) throw err
log.transports.console.level = false
}
}
}
function isBrokenPipe(err: unknown) {
return typeof err === "object" && err !== null && "code" in err && err.code === "EPIPE"
}