Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error logging for JS/TS ping test #119

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion multidim-interop/js/v0.41/test/ping.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('ping test', () => {

try {
if (isDialer) {
const otherMa = (await redisProxy(["BLPOP", "listenerAddr", timeoutSecs]).catch(err => { throw new Error("Failed to wait for listener") }))[1]
const otherMa = (await redisProxy(["BLPOP", "listenerAddr", timeoutSecs]).catch(err => { throw new Error(`Failed to wait for listener: ${err}`) }))[1]
console.log(`node ${node.peerId} pings: ${otherMa}`)
const rtt = await node.ping(multiaddr(otherMa))
console.log(`Ping successful: ${rtt}`)
Expand All @@ -99,6 +99,13 @@ describe('ping test', () => {
throw new Error("Failed to wait for dialer to finish")
}
}
} catch (err: any) {
if (err instanceof AggregateError) {
console.error(`unexpected exception in ping test: ${err}\n Errors: ${err.errors}`)
} else {
console.error(`unexpected exception in ping test: ${err}`)
}
Comment on lines +104 to +107
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am no JS expert but I think if you pass the err as an argument to console.error, it will display a nice stacktrace.

Suggested change
console.error(`unexpected exception in ping test: ${err}\n Errors: ${err.errors}`)
} else {
console.error(`unexpected exception in ping test: ${err}`)
}
console.error(`unexpected exception in ping test: ${err}\n Errors: ${err.errors}`)
} else {
console.error(`unexpected exception in ping test`, err)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be. Feel free to take over this PR by the way @MarcoPolo. You probably know better what you want to do with this suggestion and PR. My intention was more to share the need for better error logging in case the happy path is not being followed.

throw err
} finally {
try {
// We don't care if this fails
Expand Down