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

Uncaught error: Cannot assign to read only property 'stack' of object 'Error' #414

Closed
DamodarSojka opened this issue Dec 8, 2017 · 8 comments

Comments

@DamodarSojka
Copy link

DamodarSojka commented Dec 8, 2017

When calling:

this.Stripe.charges.create({
                    amount: 49900,
                    currency: "GBP",
                    description: "Subscription",
                    source: token,
                })

with 4000000000000341 (Attaching this card to a Customer object succeeds, but attempts to charge the customer fail.) I receive the following error:

Uncaught error: Cannot assign to read only property 'stack' of object 'Error', stack: TypeError: Uncaught error: Cannot assign to read only property 'stack' of object 'Error'

When the code is run with a "normal card" (for example: 4242424242424242) everything works fine.
Stack trace:

TypeError: Uncaught error: Cannot assign to read only property 'stack' of object 'Error'
at Constructor.populate (/server/node_modules/stripe/lib/Error.js:36:16)
at Constructor._Error (/server/node_modules/stripe/lib/Error.js:11:17)
at Constructor (/server/node_modules/stripe/lib/utils.js:124:13)
at Constructor (/server/node_modules/stripe/lib/utils.js:124:13)
at IncomingMessage.<anonymous> (/server/node_modules/stripe/lib/StripeResource.js:177:13)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1045:12)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickDomainCallback (internal/process/next_tick.js:198:9)

"stripe": "^5.3.0"
alpine-node:8.1.0

@ob-stripe
Copy link
Contributor

@DamodarSojka How are you assigning this.Stripe?

@DamodarSojka
Copy link
Author

I have tried both
import * as Stripe from "stripe";
...

this.Stripe = new Stripe(API_KEY) ; (with @types/stripe)
and
this.Stripe = require("stripe")(API_KEY);

@ob-stripe
Copy link
Contributor

I cannot seem to reproduce this on my end. Do you think you can provide a minimal example to reproduce the issue? You can use source: "tok_chargeCustomerFail" instead of a client-side created token.

@DamodarSojka
Copy link
Author

Do you think you can provide a minimal example to reproduce the issue? - I would love to! Not sure how to approach that however...

Same issue when using source: "tok_chargeCustomerFail". Btw, I didn't know I can simulate invalid token like that, is there a list of those somewhere?

@ob-stripe
Copy link
Contributor

ob-stripe commented Dec 10, 2017

I would love to! Not sure how to approach that however...

If you can reliably reproduce the issue, try stripping the code until you get to the bare minimum needed to showcase the issue, and share the code here (you can use https://gist.github.com or https://pastebin.com if the code is too long).

Btw, I didn't know I can simulate invalid token like that, is there a list of those somewhere?

Yes, in the testing doc page, you can click the "Tokens" tab to show static test tokens.

@DamodarSojka
Copy link
Author

DamodarSojka commented Dec 10, 2017

It seems that this code makes the stripe code to fail:

Object.defineProperty(Error.prototype, "stack", {
    configurable: true,
    enumerable: true,
});

It is meant to help with logging in hapi. Read more here: hapijs/hapi#2744

@ob-stripe
Copy link
Contributor

ob-stripe commented Dec 10, 2017

Thanks! I was able to reproduce the issue with this code:

Object.defineProperty(Error.prototype, "stack", {
  configurable: true,
  enumerable: true,
});

this.Stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);

this.Stripe.charges.create({
  amount: 400,
  currency: 'usd',
  source: 'tok_chargeCustomerFail',
});

When you call defineProperties, by default the property is set to read-only. Simply adding writable: true to the list of property descriptors should solve the issue:

Object.defineProperty(Error.prototype, "stack", {
  configurable: true,
  enumerable: true,
  writable: true,
});
...

Can you give it a try and let me know if that solves the problem for you?

@DamodarSojka
Copy link
Author

Adding writable: true solves the problem. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants