Skip to content

Commit e6b4158

Browse files
authored
fix: error logging in firefox (#2768)
Firefox has an error type with a `.stack` property that is an empty string, so guard on the various properties being empty before logging them.
1 parent 75301ac commit e6b4158

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/logger/src/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ debug.formatters.a = (v?: Multiaddr): string => {
7979

8080
// Add a formatter for stringifying Errors
8181
debug.formatters.e = (v?: Error): string => {
82-
return v == null ? 'undefined' : v.stack ?? v.message
82+
return v == null ? 'undefined' : notEmpty(v.stack) ?? notEmpty(v.message) ?? v.toString()
8383
}
8484

8585
export interface Logger {
@@ -220,3 +220,17 @@ export function enable (namespaces: string): void {
220220
export function enabled (namespaces: string): boolean {
221221
return debug.enabled(namespaces)
222222
}
223+
224+
function notEmpty (str?: string): string | undefined {
225+
if (str == null) {
226+
return
227+
}
228+
229+
str = str.trim()
230+
231+
if (str.length === 0) {
232+
return
233+
}
234+
235+
return str
236+
}

0 commit comments

Comments
 (0)