mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-15 09:02:35 +00:00
fix(desktop): suppress EPIPE errors in console transport (#25980)
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user