Skip to content

Commit

Permalink
fix: error logging in firefox (#2768)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
achingbrain authored Oct 22, 2024
1 parent 75301ac commit e6b4158
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion packages/logger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ debug.formatters.a = (v?: Multiaddr): string => {

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

export interface Logger {
Expand Down Expand Up @@ -220,3 +220,17 @@ export function enable (namespaces: string): void {
export function enabled (namespaces: string): boolean {
return debug.enabled(namespaces)
}

function notEmpty (str?: string): string | undefined {
if (str == null) {
return
}

str = str.trim()

if (str.length === 0) {
return
}

return str
}

0 comments on commit e6b4158

Please sign in to comment.