Skip to content

Commit

Permalink
Clean up full errors being logged (elastic#174440)
Browse files Browse the repository at this point in the history
## Summary

Fix a few logging calls where the full `Error` object was being logged,
either as string representation in the message, or as log meta.
  • Loading branch information
pgayvallet authored Jan 9, 2024
1 parent de961a5 commit 8186fc7
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@ describe('getPayloadSize', () => {
} as unknown as Response,
logger
);
expect(logger.warn.mock.calls[0][0]).toMatchInlineSnapshot(
`"Failed to calculate response payload bytes."`
);
expect(logger.warn.mock.calls[0][0]).toMatchInlineSnapshot(`
"Failed to calculate response payload bytes: Converting circular structure to JSON
--> starting at object with constructor 'Object'
--- property 'circular' closes the circle"
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export function getResponsePayloadBytes(response: Response, log: Logger): number
// We intentionally swallow any errors as this information is
// only a nicety for logging purposes, and should not cause the
// server to crash if it cannot be determined.
log.warn('Failed to calculate response payload bytes.', e);
log.warn(`Failed to calculate response payload bytes: ${e.message}`);
}

return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const convertModelVersionTransformFn = ({
const result = modelTransformFn(doc, context);
return { transformedDoc: result.document, additionalDocs: [] };
} catch (error) {
log.error(error);
log.error(`Error trying to transform document: ${error.message}`);
throw new TransformSavedObjectDocumentError(error, virtualVersion);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function convertMigrationFunction(

return { transformedDoc: result, additionalDocs: [] };
} catch (error) {
log.error(error);
log.error(`Error trying to transform document: ${error.message}`);
throw new TransformSavedObjectDocumentError(error, version);
}
};
Expand Down
6 changes: 3 additions & 3 deletions packages/kbn-health-gateway-server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export async function bootstrap() {
server = new Server({ config: configService, logger });
serverStart = await server.start();
} catch (e) {
log.error(`Failed to start Server: ${e}`);
log.error(`Failed to start Server: ${e.message}`);
process.exit(1);
}

Expand All @@ -46,7 +46,7 @@ export async function bootstrap() {
kibanaService = new KibanaService({ config: configService, logger });
await kibanaService.start({ server: serverStart });
} catch (e) {
log.error(`Failed to start Kibana service: ${e}`);
log.error(`Failed to start Kibana service: ${e.message}`);
process.exit(1);
}

Expand All @@ -58,7 +58,7 @@ export async function bootstrap() {
};

process.on('unhandledRejection', async (err: Error) => {
log.error(err);
log.error(`Unhandled rejection: ${err.message}`);
await attemptGracefulShutdown(1);
});

Expand Down

0 comments on commit 8186fc7

Please sign in to comment.