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

Errors miss useful stack traces #1707

Closed
oleg-codaio opened this issue Mar 13, 2023 · 2 comments
Closed

Errors miss useful stack traces #1707

oleg-codaio opened this issue Mar 13, 2023 · 2 comments
Labels

Comments

@oleg-codaio
Copy link

oleg-codaio commented Mar 13, 2023

Describe the bug

When using stripe-node, API errors seem to lose the full stack trace, making it hard to debug and find the code that triggered a particular error.

For instance, if I make a bad customers.retrieve() call (with an invalid customer ID), I get an error with the following stack trace:

Error: No such customer: 'some_fake_id'
    at Function.generate (/somedir/node_modules/.pnpm/[email protected]/node_modules/stripe/lib/Error.js:38:24)
    at res.toJSON.then.StripeAPIError.message (/somedir/node_modules/.pnpm/[email protected]/node_modules/stripe/lib/RequestSender.js:104:43)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

To Reproduce

  1. Trigger a failing Stripe network request, such as customers.retrieve
  2. Observe the thrown error's stack trace

Expected behavior

I'd expect the stack trace to contain the stack up to where the Stripe API request was made. Instead, I only get a partial internal stack.

Code snippets

No response

OS

macOS

Node version

Node v16.17.1

Library version

11.7.0

API version

2022-11-15

Additional context

See also: #118

@oleg-codaio
Copy link
Author

To leave some notes on a proposed fix, I think the issue is that async stack traces don't work due to use of .then() directly on Promises, instead of await:

if (statusCode === 401) {
err = new StripeAuthenticationError(jsonResponse.error);
} else if (statusCode === 403) {
err = new StripePermissionError(jsonResponse.error);
} else if (statusCode === 429) {
err = new StripeRateLimitError(jsonResponse.error);
} else {
err = StripeError.generate(jsonResponse.error);
}

One solution is to save the original stack trace when the call is made via new Error().stack, then splat it into the stack of any thrown error later. This would have a small penalty of constructing stack traces on every Stripe request (which I'd imagine pales in comparison to the actual network request), so if that's a concern then this could be made optional too.

@anniel-stripe
Copy link
Contributor

anniel-stripe commented Mar 14, 2023

Hi, thanks for submitting a bug report! I'm going to close this issue as a duplicate of #1542, where this problem is being tracked. #1066 also raises this issue, and the discussion there gives workarounds there that might work for you in the meantime.

One solution is to save the original stack trace when the call is made via new Error().stack, then splat it into the stack of any thrown error later. This would have a small penalty of constructing stack traces on every Stripe request (which I'd imagine pales in comparison to the actual network request), so if that's a concern then this could be made optional too.

The overhead from constructing stack traces is a definitely a concern here - we'd like to approach supporting async stack traces by actually converting our logic to be async, which is more than a quick fix.

@anniel-stripe anniel-stripe closed this as not planned Won't fix, can't repro, duplicate, stale Mar 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants