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

Proposal to return nil pointers instead of structs on request error #1647

Open
anniel-stripe opened this issue Apr 21, 2023 · 1 comment
Open

Comments

@anniel-stripe
Copy link
Contributor

anniel-stripe commented Apr 21, 2023

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

This feature request is to track community interest in stripe-go API calls returning a nil pointer when the error is not nil. The current behavior in stripe-go when the API call errors is to return both an error and a pointer to a struct with empty / zero value fields.

We've recently been informed that stripe-go does not follow the typical Go convention of returning the zero value (nil in the case of pointers) when an API call function returns a non-nil error value. This convention is not officially documented anywhere as far as we know, but is generally followed (see this related StackOverflow post).

Please feel free to upvote or comment if you would like this feature in stripe-go (or comment with arguments against making this change).

Describe the solution you'd like

In the following function call to create a new payment intent given bad params which raise an error

pi, err := paymentintent.New(badParams) // errors

Old behavior: pi is a pointer to a struct with empty fields on error
New behavior: pi is nil on error

Describe alternatives you've considered

No response

Additional context

Related links:
Is it conventional to return both value and error from function at the same time SO post
Stripe docs for error handling

@epelc
Copy link
Contributor

epelc commented Oct 10, 2023

This would be much more inline with typical go apis.

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

No branches or pull requests

2 participants