From 3c0b27e7c23f7a8009310aa84bf424e09c0aefef Mon Sep 17 00:00:00 2001 From: Geoffrey Hayes Date: Tue, 13 Jul 2021 18:48:14 -0700 Subject: [PATCH] Add Stack Trace from Call-site not Error site Due to the async callback nature of sendAndWaitForEvents, errors are raised in the callback code, which leads to an error's stacktrace being just that, in some generic callback code. This patch captures a backtrace at the original callsite and then attaches that to an error before it's returned. As such, it's possible to give the user a more helpful error. It's a bit of a hack, but not utilizing any undefined behavior. --- integration/util/scenario/event_tracker.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration/util/scenario/event_tracker.js b/integration/util/scenario/event_tracker.js index f2c677997..b23a93fe1 100644 --- a/integration/util/scenario/event_tracker.js +++ b/integration/util/scenario/event_tracker.js @@ -119,6 +119,7 @@ class EventTracker { } sendAndWaitForEvents(call, opts = {}) { + let stackTrace = new Error().stack; opts = { onFinalize: true, rejectOnFailure: true, @@ -180,6 +181,7 @@ class EventTracker { ]; if (opts.rejectOnFailure && failures.length > 0) { + failures[0].stack = stackTrace; // Use original stacktrace reject(failures[0]); } else { resolve(events);