Skip to content

Commit 29c4438

Browse files
author
Dierk Koenig
committed
fix: make sure logging with the lineSupportFormatter works in Safari again after they changed the stack frame depth
1 parent 9f9913d commit 29c4438

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/kolibri/logger/loggingSupport.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ const lineSupportFormatter = context => level => msg => {
5555
throw Error("logger");
5656
} catch(e) {
5757
const stackFrames = e.stack.split("\n");
58-
line = stackFrames[5]; // as long as the logger impl. does not chane, the call site is always 5 levels deep in the stack
58+
// Safari has removed the "Error: logger" from the stack frames, while chrome and firefox have it
59+
// Maintainer note: when the test cases fail for a certain browser only, this is likely the culprit
60+
const offset = stackFrames[0].match("Error") ? 1 : 0;
61+
line = stackFrames[4+offset]; // as long as the logger impl. does not change, the call site is always so deep in the stack
5962
}
6063
return `${msg} ${line} ${context} ${level}`;
6164
};

0 commit comments

Comments
 (0)