Fix bug with undefined file causing logging to throw an exception

This commit is contained in:
Fabian Stamm 2020-04-21 01:03:54 +02:00
parent 511bdf127f
commit 4420fb13ea
2 changed files with 9 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@hibas123/logging", "name": "@hibas123/logging",
"version": "2.4.2", "version": "2.4.3",
"description": "", "description": "",
"main": "out/index.js", "main": "out/index.js",
"types": "out/index.d.ts", "types": "out/index.d.ts",

View File

@ -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); let newF = file_raw.file.substring(PROJECT_ROOT.length);
if (newF.startsWith("/") || newF.startsWith("\\")) if (newF.startsWith("/") || newF.startsWith("\\"))
@ -342,7 +346,9 @@ export class LoggingBase {
file_raw.file = newF; file_raw.file = newF;
} }
let file = `${file_raw.file}:${file_raw.line}:${file_raw.column || 0}`; let file = `${file_raw.file || "<unknown>"}:${file_raw.line}:${
file_raw.column || 0
}`;
let type_str = LoggingTypes[type].toUpperCase().padEnd(5, " "); let type_str = LoggingTypes[type].toUpperCase().padEnd(5, " ");
let type_format: Format[] = []; let type_format: Format[] = [];