Skip to content

Commit ceb9e21

Browse files
review: log { err } in failure guards so stacks survive
String interpolation dropped Error stack traces; { err } is the house idiom (src/server.js:1127), pino serializes it with stack and console prints it whole, and it handles non-Error throws without touching .message — which also retires the errMessage() helper from the previous round. All three guard sites (mountApp fail, both ws.route paths). Suite 1024/1024; non-Error regression tests unchanged and passing.
1 parent 92ffb28 commit ceb9e21

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

src/plugins.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,6 @@ export function makePluginLog(base) {
6060
return { log: call('info'), info: call('info'), warn: call('warn'), error: call('error'), debug: call('debug') };
6161
}
6262

63-
/**
64-
* A loggable message from whatever a plugin threw — handlers can throw
65-
* non-Errors (strings, undefined), and the failure guards must never
66-
* throw themselves while reporting one.
67-
*/
68-
export function errMessage(err) {
69-
return err instanceof Error ? err.message : String(err);
70-
}
71-
7263
/** Same normalization appPaths applies: no trailing slash, must be '/x…'. */
7364
export function normalizePrefix(p) {
7465
if (typeof p !== 'string') return '';
@@ -196,7 +187,7 @@ export async function loadPlugins(fastify, entries, ctx) {
196187
// as ws.route below): log, answer 500 if nothing went out yet,
197188
// else drop the one affected socket.
198189
const fail = (res, err) => {
199-
log.error(`plugin ${id}: mounted app handler failed: ${errMessage(err)}`);
190+
log.error({ err }, `plugin ${id}: mounted app handler failed`);
200191
if (!res.headersSent && !res.writableEnded) {
201192
res.statusCode = 500;
202193
res.end();
@@ -233,11 +224,11 @@ export async function loadPlugins(fastify, entries, ctx) {
233224
// takes the host down: log it and close the one affected socket.
234225
try {
235226
Promise.resolve(handler(socket, request)).catch((err) => {
236-
log.error(`plugin ${id}: ws handler failed: ${errMessage(err)}`);
227+
log.error({ err }, `plugin ${id}: ws handler failed`);
237228
socket.terminate?.();
238229
});
239230
} catch (err) {
240-
log.error(`plugin ${id}: ws handler failed: ${errMessage(err)}`);
231+
log.error({ err }, `plugin ${id}: ws handler failed`);
241232
socket.terminate?.();
242233
}
243234
});

0 commit comments

Comments
 (0)