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

fix: Standarize/disambiguate return from Parse #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nima
Copy link

@nima nima commented Aug 26, 2022

problem: digest.Parse (prototype func Parse(string) (Digest, error)), returns the tuple (Digest, error). The expected behavior of a function in Golang that returns such, i.e., (Object, error), is that either returns (<something>, nil) (form A), or otherwise (<nothing>, <error>) (form B)--but not (<something>, <error>) (form C). This is, however, what this function does.

This is a very minor fix, since it is also expected that callers first pay attention to the error returned, before looking at the datum. And so, we can drop this PR if people deem it unnecessary. When I first made this change, it was because I came across a use case in oras-go where the caller ended up using the datum despite an error, which has now been corrected.

change: Make it return one of the two valid forms (forms A and B), and not the third (form C).

cc: @AkihiroSuda, @thaJeztah

supersedes: #76

@nima nima force-pushed the disambiguate-parse-return branch from 84a4c09 to 5b2277a Compare August 26, 2022 00:52
@stevvooe
Copy link
Contributor

While technically idiomatic, there are cases where you'd return something in the case of an error. Here, I don't think that would be validate. To users of the package, I would really recommend to always check error before using the return result.

However, since this would actually be a breaking change, I don't know that we should fix this.

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.

2 participants