mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-19 06:59:56 +02:00
fix(ui): include error name and message in forwarded logs
WebKit (macOS WKWebView) omits the "Name: message" header from Error.stack, so forwarding only the stack hid the real cause of failures. Prepend the error name, message and optional cause before the stack so daemon RPC errors surface in gui-client.log.
This commit is contained in:
@@ -21,11 +21,25 @@ let inForward = false;
|
||||
let windowStart = 0;
|
||||
let windowCount = 0;
|
||||
|
||||
// WebKit (macOS WKWebView) omits the "Name: message" header from Error.stack,
|
||||
// so a bare stack hides the real cause. Prepend name+message, then the stack.
|
||||
function formatError(e: Error): string {
|
||||
const head = `${e.name}: ${e.message}`;
|
||||
const rawCause = (e as { cause?: unknown }).cause;
|
||||
const cause =
|
||||
rawCause instanceof Error
|
||||
? `\ncaused by ${rawCause.name}: ${rawCause.message}`
|
||||
: rawCause !== undefined
|
||||
? `\ncaused by ${String(rawCause)}`
|
||||
: "";
|
||||
return e.stack && !e.stack.startsWith(head) ? `${head}${cause}\n${e.stack}` : `${head}${cause}`;
|
||||
}
|
||||
|
||||
function format(args: unknown[]): string {
|
||||
return args
|
||||
.map((a) => {
|
||||
if (typeof a === "string") return a;
|
||||
if (a instanceof Error) return a.stack || a.message;
|
||||
if (a instanceof Error) return formatError(a);
|
||||
try {
|
||||
return JSON.stringify(a);
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user