question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use async functions within request handling code

See original GitHub issue

Is your feature request related to a problem? Please describe.

Currently, there is a lot of setTimeouts and other non-async-y code that means that we cannot take advantage of V8’s async stack trace feature. This means that we lose out on stack traces, the bare minimum that one would want for debugging an issue in production.

While support for the async stack trace feature came in Node 12, support for the async/await syntax (which would allow for users of newer node to get a stack trace) has been present from Node 7.

Describe the solution you’d like

At the very least, please use async/await syntax within the core request calling methods (StripeResource, StripeMethod), and remove usage of raw setTimeout, instead doing things like await Promise((resolve, reject) => setTimeout(reject, 0)) to make sure that async stack traces are maintained.

Doing this pervasively should make the code easier to manage, reduce a lot of indentation, and be functionally equivalent given how this all works.

Describe alternatives you’ve considered

Monkeypatching is theoretically possible, and there are options to capture error traces myself, but that involves creating spurious error objects all over and increasing difficulties of updating stripe-node.

Additional context

https://github.com/stripe/stripe-node/issues/1066 is an example of this issue

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ramya-stripecommented, Nov 18, 2022

Hey @rtpg

Thanks for your patience. We agree that this is crucial for the debugging experience. This would be a bit more than a quick fix and so we will be working on this in the coming months.

1reaction
ramya-stripecommented, Nov 11, 2022

Thanks for getting back to us @rtpg We will take another look next week

Read more comments on GitHub >

github_iconTop Results From Across the Web

async function - JavaScript - MDN Web Docs - Mozilla
The async function declaration declares an async function where the await keyword is permitted within the function body. The async and await ...
Read more >
Using async/await in Express - Zell Liew
The easiest way to use async/await in Express is use express-async-handler. This article shows you why, and how you can use it.
Read more >
Error handling with Async/Await in JS | by Ian Segers | ITNEXT
Learn error handling in JS with sync and async code and some caveats. ... We call thisThrows() in an async function and await...
Read more >
Async/await - The Modern JavaScript Tutorial
The word “async” before a function means one simple thing: a function always returns a promise. Other values are wrapped in a resolved...
Read more >
How to Handle Async Code in JavaScript | AppSignal Blog
An async function will always return a promise, implicitly making it easier to work with. The await keyword can only be used in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found