Preserve stack traces for async operations#2688
Merged
Conversation
jar-stripe
requested changes
Apr 17, 2026
Contributor
jar-stripe
left a comment
There was a problem hiding this comment.
We should have a utility for getting the stack, given there are a few places use that. That's the biggest requested change, the others would be nice to consider/test for.
jar-stripe
approved these changes
Apr 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
Because of the way the internals of the SDK's async HTTP calling code are structured, when we throw an error, it loses its original stack trace. Users have only been able to trace issues back to where our HTTP calls originate from, not where in their code caused the HTTP call that failed.
The best solution is to use promises all the way down our HTTP chain, which will let node resolve stack traces as we'd expect. But that's a pretty big internal change and is part of why the team hadn't prioritized it in the past.
We talked it over this week and decided to take a more tactical approach: by manually instantiating an unthrown error before doing any async operations, we can reference its call stack if the async operation later fails. That gives us pretty usable tracebacks (seen below). I've also manually confirmed that it works for
autoPagingEachandautoPagingToArray.As far as I can tell, we didn't try this before because of perceived performance implications, but based on local testing with real API calls, the difference is negligible (approx. 30ms / request, which is indistinguishable from network jitter). We'll still probably go through and simplify this code in the future, but this is a reasonable stopgap until we get to that.
before:
after:
What?
See Also