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

prevent nil panic #3922

Merged
merged 1 commit into from Aug 4, 2015
Merged

prevent nil panic #3922

merged 1 commit into from Aug 4, 2015

Conversation

deads2k
Copy link
Contributor

@deads2k deads2k commented Jul 27, 2015

Fixes #3529, Fixes #3959

I can't reproduce the panic, but this prevents panics in the casts.

@liggitt
Copy link
Contributor

liggitt commented Jul 27, 2015

Shouldn't these trigger off non-nil errors, not nil object checks?

@deads2k
Copy link
Contributor Author

deads2k commented Jul 27, 2015

Shouldn't these trigger off non-nil errors, not nil object checks?

I'd rather check for the condition actually causing the failure in case crazy things happen. No matter what the value of the error is, if the obj is nil, it will never be castable.

@liggitt
Copy link
Contributor

liggitt commented Jul 28, 2015

Hmm… if it's possible to return nil in a non-error case, that impl is broken. Should sweep for that if we're not confident in it, and short circuit on non-nil err here

@deads2k
Copy link
Contributor Author

deads2k commented Jul 28, 2015

Hmm… if it's possible to return nil in a non-error case, that impl is broken. Should sweep for that if we're not confident in it, and short circuit on non-nil err here

I don't disagree that it would be broken at a lower level. I'm just struggling to come up with a valid reason to avoid checking for the condition that will actually cause an error and handling in a reasonable way.

@deads2k deads2k mentioned this pull request Aug 3, 2015
@liggitt
Copy link
Contributor

liggitt commented Aug 3, 2015

I just don't like assuming the value is castable in an error condition.

@deads2k
Copy link
Contributor Author

deads2k commented Aug 3, 2015

I just don't like assuming the value is castable in an error condition.

I don't like assuming I should throw away the returned value in the case of an error. This is supposed to be an object whose only purpose is to pass through to storage in a type-safe way. Assuming an error means a nil return value violates that principle.

@liggitt
Copy link
Contributor

liggitt commented Aug 3, 2015

compromise?

obj, err := s.Create(ctx, node)
if role, ok := obj.(*authorizationapi.ClusterRole); ok {
  return role, err
}
if err != nil {
  return nil, err
}
return nil, errors.New("Unexpected type: ...")

@liggitt liggitt self-assigned this Aug 3, 2015
@smarterclayton
Copy link
Contributor

You should not cast values if err != nil. The general go convention is "if err != nil, all other return values are suspect unless defined otherwise, and if defined otherwise, shoot the reviewer who allowed it because that's crazy talk".

@deads2k
Copy link
Contributor Author

deads2k commented Aug 4, 2015

I don't like it. Waaa. [merge]

@deads2k
Copy link
Contributor Author

deads2k commented Aug 4, 2015

Oh, just in case you didn't look, I did change it to err != nil, even though I don't like it.

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_origin/2884/) (Image: devenv-fedora_2101)

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 74a2d68

@openshift-bot
Copy link
Contributor

[Test]ing while waiting on the merge queue

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/3877/)

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 74a2d68

openshift-bot pushed a commit that referenced this pull request Aug 4, 2015
@openshift-bot openshift-bot merged commit 2f017f4 into openshift:master Aug 4, 2015
@deads2k deads2k deleted the fix-panic branch September 1, 2015 12:55
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

Successfully merging this pull request may close these issues.

None yet

4 participants