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

azblob.NewSharedKeyCredential should not panic #42

Closed
jamesjoshuahill opened this issue Apr 24, 2018 · 4 comments
Closed

azblob.NewSharedKeyCredential should not panic #42

jamesjoshuahill opened this issue Apr 24, 2018 · 4 comments

Comments

@jamesjoshuahill
Copy link

When we create a new Shared Key Credential, and pass in a account key which is an invalid base 64 string, the library panics. Normally in Golang a panic means something went unexpectedly wrong, which is not the case in this function call, and the error can be easily returned.

For us as consumers of the package we have to recover the panic in order to prevent our program from exiting unexpectedly. Also, the error passed to panic does not indicate that it was caused by an invalid account key.

Would you accept a PR?

@jamesjoshuahill and @tinygrasshopper

jamesjoshuahill pushed a commit to cloudfoundry/backup-and-restore-sdk-release that referenced this issue Apr 24, 2018
By duplicating the current error check we can avoid using recover.
We reported this issue: Azure/azure-storage-blob-go#42

[#156302315]

Signed-off-by: Josh Hill <jhill@pivotal.io>
@JeffreyRichter
Copy link
Member

JeffreyRichter commented Apr 25, 2018 via email

@tombuildsstuff
Copy link

@JeffreyRichter to give a counter point here, we load clients on demand using an access key, if the credentials are invalid (such as when the access tokens have been cycled) it’s perfectly safe to pull the latest access key and try again. This policy would be a blocker for us adopting this SDK, since it means users would have unexpected crashes (which isn’t acceptable for our use-case) - as such I’d like to +1 this request to use errors rather than panics; as has been done in the Go SDK.

Regarding method chaining - this is less prevalent in Go than other languages (such as C# or Java), since most complex methods can return errors - as such I believe the downsides to this approach outweigh the benefits of panicking here

Thanks!

cc @joshgav

@JeffreyRichter
Copy link
Member

JeffreyRichter commented Jul 2, 2018 via email

@devigned
Copy link
Member

devigned commented Aug 7, 2018

So, from what you are describing, I do not see any potential blocker for you adopting the library.
And also, if a panic did occur, then you can use Go’s defer/recover mechanism to recover from this and do what you want. So, you really should be fine.

I don't agree that one should use recover in this situation. If you are taking input from a user, you can't control if they fat finger something. Using a panic in this type of situation is excessive and unlike any other library I've used.

Recover does not provide the same experience as the common error return. The return is close the problem where recover is distant. Recover requires handling in a defer, where error can be handled in normal control flow. It's apples and oranges.

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

4 participants