Skip to content

Commit 8d16c9f

Browse files
author
Lasim
committed
fix(satellite): improve error handling for unhandled rejections and exceptions
1 parent 1b371f8 commit 8d16c9f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

services/satellite/src/server.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,17 @@ function validateSatelliteName(name: string | undefined, logger?: any): void {
125125

126126
export async function createServer() {
127127
// Add global error handlers to catch unhandled errors
128+
// Note: These run before Fastify logger is initialized, so we write to stderr directly
128129
process.on('unhandledRejection', (reason, promise) => {
129-
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
130+
const errorMessage = reason instanceof Error ? reason.message : String(reason);
131+
process.stderr.write(`FATAL: Unhandled Rejection at: ${String(promise)} reason: ${errorMessage}\n`);
130132
process.exit(1);
131133
});
132134

133135
process.on('uncaughtException', (error) => {
134-
console.error('Uncaught Exception:', error);
136+
const errorMessage = error instanceof Error ? error.message : String(error);
137+
const errorStack = error instanceof Error ? error.stack : '';
138+
process.stderr.write(`FATAL: Uncaught Exception: ${errorMessage}\n${errorStack || ''}\n`);
135139
process.exit(1);
136140
});
137141

0 commit comments

Comments
 (0)