Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

Commit aec3223

Browse files
staticoclaude
andcommitted
Add global error handler with stack trace logging
Appends errors to ~/.config/meshtastic-cli/error.log 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f827871 commit aec3223

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

src/index.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,44 @@
11
import React from "react";
22
import { render } from "ink";
3+
import { appendFileSync, mkdirSync, existsSync } from "fs";
4+
import { join } from "path";
5+
import { homedir } from "os";
36
import { PacketStore, NodeStore } from "./protocol";
47
import { App } from "./ui/App";
58
import { initDb, clearDb, getDbPath } from "./db";
69
import { getSetting, DEFAULT_MESHVIEW_URL } from "./settings";
710

11+
// Global error handler - append errors to log file
12+
const ERROR_LOG_DIR = join(homedir(), ".config", "meshtastic-cli");
13+
const ERROR_LOG_PATH = join(ERROR_LOG_DIR, "error.log");
14+
15+
function logError(type: string, error: Error | unknown) {
16+
try {
17+
if (!existsSync(ERROR_LOG_DIR)) {
18+
mkdirSync(ERROR_LOG_DIR, { recursive: true });
19+
}
20+
const timestamp = new Date().toISOString();
21+
const message = error instanceof Error
22+
? `${error.message}\n${error.stack || ""}`
23+
: String(error);
24+
const entry = `\n[${timestamp}] ${type}\n${message}\n${"─".repeat(60)}\n`;
25+
appendFileSync(ERROR_LOG_PATH, entry);
26+
} catch {
27+
// Ignore logging errors
28+
}
29+
}
30+
31+
process.on("uncaughtException", (error) => {
32+
logError("UNCAUGHT EXCEPTION", error);
33+
console.error("Fatal error:", error.message);
34+
console.error(`Stack trace saved to ${ERROR_LOG_PATH}`);
35+
process.exit(1);
36+
});
37+
38+
process.on("unhandledRejection", (reason) => {
39+
logError("UNHANDLED REJECTION", reason);
40+
});
41+
842
// Parse CLI arguments
943
const args = process.argv.slice(2);
1044
let address = "192.168.0.123";

0 commit comments

Comments
 (0)