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

Error early when params not specified for card functions #484

Merged
merged 2 commits into from
Oct 24, 2017

Conversation

brandur
Copy link
Contributor

@brandur brandur commented Oct 23, 2017

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.

r? @remi-stripe

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.
@@ -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 {
Copy link
Contributor

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?

Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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!

Copy link
Contributor

@remi-stripe remi-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@brandur-stripe brandur-stripe merged commit a7981e6 into master Oct 24, 2017
@brandur-stripe brandur-stripe deleted the brandur-require-params branch October 24, 2017 16:06
@brandur-stripe
Copy link
Contributor

Thanks Remi. Released as 28.4.1.

nadaismail-stripe pushed a commit that referenced this pull request Oct 18, 2024
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] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants