-
Notifications
You must be signed in to change notification settings - Fork 460
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
Error early when params not specified for card functions #484
Conversation
Card-related API calls are a bit of an unusual case because we need to have an instantiated params struct in order to determine the correct URL to which to make the request. Previously, if a `nil` was passed to any of these functions, we'd panic as we tried to access one of its members. This patch just makes the params requirement a little more explicit by returning an error if any of card functions is called with `nil` params. Fixes #483.
848cfb6
to
6aacada
Compare
@@ -129,6 +141,10 @@ func Del(id string, params *stripe.CardParams) (*stripe.Card, error) { | |||
} | |||
|
|||
func (c Client) Del(id string, params *stripe.CardParams) (*stripe.Card, error) { | |||
if params == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're already doing if params != nil {
below (not visible) so it's redundant. Should you fix the one below in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point. Unfortunately the other one would still result in a panic because of the check on params.Account
immediately afterwards, so I've taken that one out in favor of my addition.
|
||
return &Iter{stripe.GetIter(lp, body, func(b *form.Values) ([]interface{}, stripe.ListMeta, error) { | ||
list := &stripe.CardList{} | ||
var err error | ||
|
||
if params == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just error above like you do in the other functions if params == nil
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, basically because List
functions only return an *Iter
(and not an error). The first opportunity we get to return an error is the first time the iterator iterates, and so the check on params
is further down than you'd expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah gotcha, that makes sense, thanks for clarifying!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks Remi. Released as 28.4.1. |
Bumps [sorbet](https://github.com/sorbet/sorbet) from 0.5.10073 to 0.5.10087. - [Release notes](https://github.com/sorbet/sorbet/releases) - [Commits](https://github.com/sorbet/sorbet/commits) --- updated-dependencies: - dependency-name: sorbet dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Card-related API calls are a bit of an unusual case because we need to
have an instantiated params struct in order to determine the correct URL
to which to make the request. Previously, if a
nil
was passed to anyof these functions, we'd panic as we tried to access one of its members.
This patch just makes the params requirement a little more explicit by
returning an error if any of card functions is called with
nil
params.Fixes #483.
r? @remi-stripe