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

stripe.Error does not work with errors.As() #1260

Closed
ffigiel opened this issue Mar 2, 2021 · 2 comments
Closed

stripe.Error does not work with errors.As() #1260

ffigiel opened this issue Mar 2, 2021 · 2 comments

Comments

@ffigiel
Copy link

ffigiel commented Mar 2, 2021

Hello!

I have a shop package with a Client type that wraps a Stripe client in a focused, higher-level interface. I am adding support for coupon codes and need to check if the error I get from Stripe means "that coupon code is invalid" or something else.

I have this

package shop

func IsNotFound(err error) bool {
        var stripeErr stripe.Error
        if errors.As(err, &stripeErr) {
                return stripeErr.Type == stripe.ErrorTypeInvalidRequest &&
                        stripeErr.Code == stripe.ErrorCodeResourceMissing
        }
        return false
}

but I get this warning in my editor, and executing this code results in a panic

second argument to errors.As must be a non-nil pointer to either a type that implements error, or to any interface type

Which is weird, as in the docs I clearly see that stripe.Error implements the error interface. I'm not sure if this is a bug in stripe-go package, the built-in errors package, or maybe I'm too tired to think. By the way, is this the correct way for checking for such an error? Please advise 🙂


Additional note: I can't just do a type assertion, because my shop.Client wraps the error with fmt.Errorf. For now I will just type-assert Unwrap()pable interface, and then type-assert stripe.Error the inner error.


My environment:

$ go version
go version go1.15.2 linux/amd64
$ grep stripe go.mod
	github.com/stripe/stripe-go/v72 v72.35.0
@brandur-stripe
Copy link
Contributor

The docs for errors.As are shockingly awful in that as far as I can tell, this is never explicitly mentioned, but it actually wants a pointer to a pointer. Make stripeErr in your code a pointer type:

var stripeErr *stripe.Error

@ffigiel
Copy link
Author

ffigiel commented Mar 3, 2021

Right, because that Error method actually takes *stripe.Error and errors.As needs a pointer to that receiver. Thank you for responding so quickly!

nadaismail-stripe added a commit that referenced this issue Oct 18, 2024
* Temp commit

* Temp checkin to switch tracks

* We appear to be ready for config import but need another first-install run.

* add import modal

* Remove changes for actual config importer to limit scope to just the config manager

* Working to improve test coverage

* got test coverage up to 83 percent

* Initial commit with new API methods

* Trivial changes for delete account config

* Adding get all account configs api method

* Intermediate commit

* More changes to bring implementation closer to doc

* Update tooling to help find the issue

* bad import statements

* Init commit of using new composite key

* More refactors

* Migration to add default field to users

* Fix so that we budget for multiple returns, as sf acct id isn't a key anymore

* Just the migration script

* init commit custom field

* Rename Stripe_Account_ID__C.field-meta.xml to Stripe_Account_ID__c.field-meta.xml

* Changing label and adding to Order information

* Changing text field to more complex structure, not showing up in the UI

* Reworking a bit, testing out deploys

* Fixing feedback

* [Multi Stripe Account] Modifying order poller (#1251)

* Adding a simple statement to the soql query

* Adding constant and using prefixed stripe field

* Update stripe_callback_handler to handle adding stripe accounts, and add provisional v2 connection statuses endpoint

* additional pieces needed for other updates

* Remove magic strings

* Added livemode to response key for status endpoint

* got initial connection loop working w/ minor bug to fix later

* Adding livemode fields to permission set, modifying order poller, adding constants

* Made things work, minimally

* Completed essential work for multi-stripe account support

* Improved test coverage: Org Wide Coverage    84%

* Account poller only polls the default user

* Fix missed debug enabling

* Add description for stripe id

* Added description to stripe account field on order.

* Button up multi-stripe account support

* Couple tweaks

* Added some nice git ignores

* Added more instructions to local dev testing

* bug bash fixes (#1265)

* bug bash fixes

* Added comments and soft delete instead of hard deleting users

* More pr feedback

* UI changes from bug bash

* Fix a bug rish was encountering

* Removed refs to connection status

* Added a comment

* Nada pr feedback

* Removing bad test

---------

Co-authored-by: Keshav Chakrapani <[email protected]>
Co-authored-by: keshavc-stripe <[email protected]>
Co-authored-by: Nada Ismail <[email protected]>
nadaismail-stripe added a commit that referenced this issue Oct 18, 2024
* multi stripe account support (#1260)

* Temp commit

* Temp checkin to switch tracks

* We appear to be ready for config import but need another first-install run.

* add import modal

* Remove changes for actual config importer to limit scope to just the config manager

* Working to improve test coverage

* got test coverage up to 83 percent

* Initial commit with new API methods

* Trivial changes for delete account config

* Adding get all account configs api method

* Intermediate commit

* More changes to bring implementation closer to doc

* Update tooling to help find the issue

* bad import statements

* Init commit of using new composite key

* More refactors

* Migration to add default field to users

* Fix so that we budget for multiple returns, as sf acct id isn't a key anymore

* Just the migration script

* init commit custom field

* Rename Stripe_Account_ID__C.field-meta.xml to Stripe_Account_ID__c.field-meta.xml

* Changing label and adding to Order information

* Changing text field to more complex structure, not showing up in the UI

* Reworking a bit, testing out deploys

* Fixing feedback

* [Multi Stripe Account] Modifying order poller (#1251)

* Adding a simple statement to the soql query

* Adding constant and using prefixed stripe field

* Update stripe_callback_handler to handle adding stripe accounts, and add provisional v2 connection statuses endpoint

* additional pieces needed for other updates

* Remove magic strings

* Added livemode to response key for status endpoint

* got initial connection loop working w/ minor bug to fix later

* Adding livemode fields to permission set, modifying order poller, adding constants

* Made things work, minimally

* Completed essential work for multi-stripe account support

* Improved test coverage: Org Wide Coverage    84%

* Account poller only polls the default user

* Fix missed debug enabling

* Add description for stripe id

* Added description to stripe account field on order.

* Button up multi-stripe account support

* Couple tweaks

* Added some nice git ignores

* Added more instructions to local dev testing

* bug bash fixes (#1265)

* bug bash fixes

* Added comments and soft delete instead of hard deleting users

* More pr feedback

* UI changes from bug bash

* Fix a bug rish was encountering

* Removed refs to connection status

* Added a comment

* Nada pr feedback

* Removing bad test

---------

Co-authored-by: Keshav Chakrapani <[email protected]>
Co-authored-by: keshavc-stripe <[email protected]>
Co-authored-by: Nada Ismail <[email protected]>

* Fixing the multi stripe account bug

* Fixing rubocop error

---------

Co-authored-by: jmather-c <[email protected]>
Co-authored-by: Nada Ismail <[email protected]>
nadaismail-stripe added a commit that referenced this issue Oct 18, 2024
* multi stripe account support (#1260)

* Temp commit

* Temp checkin to switch tracks

* We appear to be ready for config import but need another first-install run.

* add import modal

* Remove changes for actual config importer to limit scope to just the config manager

* Working to improve test coverage

* got test coverage up to 83 percent

* Initial commit with new API methods

* Trivial changes for delete account config

* Adding get all account configs api method

* Intermediate commit

* More changes to bring implementation closer to doc

* Update tooling to help find the issue

* bad import statements

* Init commit of using new composite key

* More refactors

* Migration to add default field to users

* Fix so that we budget for multiple returns, as sf acct id isn't a key anymore

* Just the migration script

* init commit custom field

* Rename Stripe_Account_ID__C.field-meta.xml to Stripe_Account_ID__c.field-meta.xml

* Changing label and adding to Order information

* Changing text field to more complex structure, not showing up in the UI

* Reworking a bit, testing out deploys

* Fixing feedback

* [Multi Stripe Account] Modifying order poller (#1251)

* Adding a simple statement to the soql query

* Adding constant and using prefixed stripe field

* Update stripe_callback_handler to handle adding stripe accounts, and add provisional v2 connection statuses endpoint

* additional pieces needed for other updates

* Remove magic strings

* Added livemode to response key for status endpoint

* got initial connection loop working w/ minor bug to fix later

* Adding livemode fields to permission set, modifying order poller, adding constants

* Made things work, minimally

* Completed essential work for multi-stripe account support

* Improved test coverage: Org Wide Coverage    84%

* Account poller only polls the default user

* Fix missed debug enabling

* Add description for stripe id

* Added description to stripe account field on order.

* Button up multi-stripe account support

* Couple tweaks

* Added some nice git ignores

* Added more instructions to local dev testing

* bug bash fixes (#1265)

* bug bash fixes

* Added comments and soft delete instead of hard deleting users

* More pr feedback

* UI changes from bug bash

* Fix a bug rish was encountering

* Removed refs to connection status

* Added a comment

* Nada pr feedback

* Removing bad test

---------

Co-authored-by: Keshav Chakrapani <[email protected]>
Co-authored-by: keshavc-stripe <[email protected]>
Co-authored-by: Nada Ismail <[email protected]>

* Fixing the multi stripe account bug

* Correcting pr feedback

* Adding new script to populate stripe account objects

* Fix merge conflicts and remove create stripe account script

* Delete dead ruby code

* Removing comments from order_poller

* Change some of the UI

* Refactor stripe callback handler

* Rename

* Remove doubled lined

* Add back state

* Fix type errors

* Fix livemode error

* Fix errors

* Add comment

* Add error

* Fixing reauth bug

* typecheck

* Update livemode

* Set livemode on state

* Convert to string

* Set livemode

* Revert v2 error

* Revert or false

* Fixing bugs with refactor

* Changing comments to be more accurate

---------

Co-authored-by: jmather-c <[email protected]>
Co-authored-by: Nada Ismail <[email protected]>
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