From 8911ac6481dbf82a0e9f590a566287d48906bf31 Mon Sep 17 00:00:00 2001 From: Michael Courtin Date: Tue, 8 Feb 2022 17:47:30 +0100 Subject: [PATCH] fix: 1702: Fix getExceptionMessageInfo() and add docu Fix getExceptionMessageInfo() function in exception-helper and add some documentation to logger.exception Closes: #1702 Signed-off-by: Michael Courtin --- .../src/main/typescript/exception/exception-helper.ts | 5 ++++- .../cactus-common/src/main/typescript/logging/logger.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/cactus-common/src/main/typescript/exception/exception-helper.ts b/packages/cactus-common/src/main/typescript/exception/exception-helper.ts index 7525bec059..2fcba2623b 100644 --- a/packages/cactus-common/src/main/typescript/exception/exception-helper.ts +++ b/packages/cactus-common/src/main/typescript/exception/exception-helper.ts @@ -38,7 +38,7 @@ export class ExceptionHelper { const exceptionMessageInfo = this.getExceptionMessageInfo(exception); const exceptionStackInfo = this.getExceptionStackInfo(exception); let content = ""; - let runtimeError = new RuntimeError(context, exceptionMessageInfo.message); + let runtimeError: RuntimeError | undefined = undefined; if (exception instanceof Error) { // scenario 1: exception is already an instance of Error / RuntimeError -> can be used directly @@ -212,6 +212,9 @@ export class ExceptionHelper { if (!exceptionHandled && isOfTypeString) { message = customExceptionPrefix + exception; exceptionHandled = true; + // as this scenario handles exception of string only type + // there is no other property and it is per se completely stringified + containsCompleteStringifiedException = true; } // scenario 4: handling of custom exceptions diff --git a/packages/cactus-common/src/main/typescript/logging/logger.ts b/packages/cactus-common/src/main/typescript/logging/logger.ts index 3e49d6e63e..bd050d7f89 100644 --- a/packages/cactus-common/src/main/typescript/logging/logger.ts +++ b/packages/cactus-common/src/main/typescript/logging/logger.ts @@ -119,6 +119,14 @@ export class Logger { } /** + * The 'exception' method is retrieving and stringify-ing the complete exception content like message + stack + custom properties (if available) in a safe and secure way + * of any arbitrary exception or whatever it might be and logging it as an error thru the usage of this logger.error() functionality. + * + * So there is no need of dealing with different exception types or checks if a stack trace etc. is available -> all is done automatically here + * Only hand in the exception and maybe some optional, additional information / context can be provided as second parameter about the scenario where the exception happened + * + * + * * Standard Exception Handling: * ============================ * logger.exception(ex);