fix: use telegram token file for sends and guard console EPIPE

This commit is contained in:
Josh Palmer
2025-12-24 18:18:48 +01:00
parent 1d8b47785c
commit 10eced9971
4 changed files with 77 additions and 45 deletions

View File

@@ -268,6 +268,10 @@ function shouldSuppressConsoleMessage(message: string): boolean {
);
}
function isEpipeError(err: unknown): boolean {
return Boolean((err as { code?: string })?.code === "EPIPE");
}
/**
* Route console.* calls through pino while still emitting to stdout/stderr.
* This keeps user-facing output unchanged but guarantees every console call is captured in log files.
@@ -321,9 +325,19 @@ export function enableConsoleCapture(): void {
level === "error" || level === "fatal" || level === "warn"
? process.stderr
: process.stderr; // in RPC/JSON mode, keep stdout clean
target.write(`${formatted}\n`);
try {
target.write(`${formatted}\n`);
} catch (err) {
if (isEpipeError(err)) return;
throw err;
}
} else {
orig.apply(console, args as []);
try {
orig.apply(console, args as []);
} catch (err) {
if (isEpipeError(err)) return;
throw err;
}
}
};