mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-01 20:42:50 +08:00
Merge pull request #6 from ZHANGTIANYAO1/claude/setup-teamspeak-bot-QBfaS
Add comprehensive error handling to prevent process crashes
This commit is contained in:
6 files changed
+31
-1
No files matched your search
@@ -128,6 +128,14 @@ export class AudioPlayer extends EventEmitter {
|
||||
this.logger.info({ ffmpeg: ffmpegBin }, "Using ffmpeg binary");
|
||||
this.ffmpeg = spawn(ffmpegBin, args, { stdio: ["ignore", "pipe", "pipe"] });
|
||||
|
||||
// Prevent stream errors from crashing the process
|
||||
this.ffmpeg.stdout!.on("error", (err) => {
|
||||
this.logger.warn({ err }, "FFmpeg stdout error");
|
||||
});
|
||||
this.ffmpeg.stderr!.on("error", (err) => {
|
||||
this.logger.warn({ err }, "FFmpeg stderr error");
|
||||
});
|
||||
|
||||
let gotFirstData = false;
|
||||
this.ffmpeg.stdout!.on("data", (chunk: Buffer) => {
|
||||
if (!gotFirstData) {
|
||||
|
||||
+3
-1
@@ -99,7 +99,9 @@ export class BotInstance extends EventEmitter {
|
||||
|
||||
private setupTsEvents(): void {
|
||||
this.tsClient.on("textMessage", (msg: TS3TextMessage) => {
|
||||
this.handleTextMessage(msg);
|
||||
this.handleTextMessage(msg).catch((err) => {
|
||||
this.logger.error({ err }, "Unhandled error in text message handler");
|
||||
});
|
||||
});
|
||||
|
||||
this.tsClient.on("disconnected", () => {
|
||||
|
||||
@@ -25,6 +25,14 @@ async function main() {
|
||||
saveConfig(CONFIG_PATH, config);
|
||||
|
||||
const logger = createLogger(LOG_DIR);
|
||||
|
||||
// Prevent unhandled errors from crashing the process
|
||||
process.on("uncaughtException", (err) => {
|
||||
logger.error({ err }, "Uncaught exception");
|
||||
});
|
||||
process.on("unhandledRejection", (reason) => {
|
||||
logger.error({ reason }, "Unhandled promise rejection");
|
||||
});
|
||||
const db = createDatabase(DB_PATH);
|
||||
|
||||
const apiServer = createApiServerManager(
|
||||
|
||||
@@ -114,6 +114,7 @@ export class TS3Client extends EventEmitter {
|
||||
await this.client.connect();
|
||||
await this.client.waitConnected();
|
||||
this.clientId = this.client.clientID();
|
||||
this.voiceFramesSent = 0;
|
||||
this.logger.info({ clientId: this.clientId }, "Logged in (visible client)");
|
||||
|
||||
// Join default channel if specified
|
||||
|
||||
@@ -67,7 +67,14 @@ export function createWebServer(options: WebServerOptions): WebServer {
|
||||
});
|
||||
}
|
||||
|
||||
server.on("error", (err) => {
|
||||
logger.error({ err }, "HTTP server error");
|
||||
});
|
||||
|
||||
const wss = new WebSocketServer({ server, path: "/ws" });
|
||||
wss.on("error", (err) => {
|
||||
logger.error({ err }, "WebSocket server error");
|
||||
});
|
||||
const cleanupWs = setupWebSocket(wss, options.botManager, logger);
|
||||
|
||||
return {
|
||||
|
||||
@@ -39,7 +39,11 @@ export function setupWebSocket(
|
||||
const message = JSON.stringify(data);
|
||||
for (const client of clients) {
|
||||
if (client.readyState === WebSocket.OPEN) {
|
||||
try {
|
||||
client.send(message);
|
||||
} catch {
|
||||
clients.delete(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user