From 4420fb13ea7e997586827604c86df4d6b0049630 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Tue, 21 Apr 2020 01:03:54 +0200 Subject: [PATCH] Fix bug with undefined file causing logging to throw an exception --- package.json | 2 +- src/base.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0ce58ce..cb0d26b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hibas123/logging", - "version": "2.4.2", + "version": "2.4.3", "description": "", "main": "out/index.js", "types": "out/index.d.ts", diff --git a/src/base.ts b/src/base.ts index b320156..1e3f4fc 100644 --- a/src/base.ts +++ b/src/base.ts @@ -334,7 +334,11 @@ export class LoggingBase { } } - if (PROJECT_ROOT && file_raw.file.startsWith(PROJECT_ROOT)) { + if ( + PROJECT_ROOT && + file_raw.file && + file_raw.file.startsWith(PROJECT_ROOT) + ) { let newF = file_raw.file.substring(PROJECT_ROOT.length); if (newF.startsWith("/") || newF.startsWith("\\")) @@ -342,7 +346,9 @@ export class LoggingBase { file_raw.file = newF; } - let file = `${file_raw.file}:${file_raw.line}:${file_raw.column || 0}`; + let file = `${file_raw.file || ""}:${file_raw.line}:${ + file_raw.column || 0 + }`; let type_str = LoggingTypes[type].toUpperCase().padEnd(5, " "); let type_format: Format[] = [];