-
Notifications
You must be signed in to change notification settings - Fork 395
RFC WIP: Define the three return states of HaveBlob as true/false/error #204
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
Conversation
|
As long as that interface is respected and (false, nil) always means not found, I'm fine. We need to fix up |
Could you point at an example of such use? I can think of things like Alternatively, a err := …HasBlob()
if err == nil {
// exists
} else if err == types.ErrBlobNotFound {
// does not exist
} else {
// unexpected error
}(perhaps switching the last two clauses, but The “ |
yeah I was thinking at that, and yeah, it's not quite the same, I'm fine with this PR though |
7ccae69 to
74906f3
Compare
74906f3 to
ce2bb67
Compare
Create /etc/containers/registries.d in (make install)
610e84d to
70a5c6f
Compare
226d282 to
31edd2b
Compare
51b536d to
f9a389f
Compare
f9a389f to
91db8ac
Compare
91db8ac to
d93d314
Compare
b1b0a8c to
7e5e9d9
Compare
|
@runcom (Low-priority) PTAL eventually. If you don’t like this, feel completely free to close it and leave the code as is, or tell me how to rewrite. |
|
LGTM (@glestaris ping just in case you're using this and it breaks for you after this change) |
7e5e9d9 to
7d96891
Compare
The current interface can return (haveBlob, _, err):
- (true, nil): blob exists
- (false, ErrBlobNotFound): blob does not exist or unknown
- (false, other non-nil): unexpected error
i.e. (haveBlob) is equivalent to (err == nil), which is both redundant
and makes the interface unnecessarily difficult to use for the typical
case where the caller wants to abort on an unexpected error, and then
decide based on haveBlob:
if err != nil && err != types.ErrBlobNotFound {
return err
}
if haveBlob { … }
Insted, define the interface to be
- (true, nil): blob exists
- (false, nil): blob does not exist or unknown
- (false, non-nil): unexpected error
which simplifies the “abort” conditional to a simple (err != nil).
A possible alternative would be to eliminate the haveBlob bool instead,
but that still requires two-clause checks for aborting, and semantically
a blob not being present is not an error, it is a succesfully obtained
return value.
Signed-off-by: Miloslav Trmač <[email protected]>
|
👍
(This drops |
7d96891 to
3d6a74b
Compare
(WIP because this includes #202 and #203 just because I am lazy to do this several times.)
@runcom PTAL: I know in #63 you have explicitly asked for
ErrBlobNotFoundto be added, but it seems to me that just makes the uses ofHaveBlobmore complex. I can live with the current code if it is indeed is more idiomatic, or perhaps I am missing a cleaner way to use it.The current interface can return
(haveBlob, _, err):(true, nil): blob exists(false, ErrBlobNotFound): blob does not exist or unknown(false,other non-nil): unexpected errori.e.
haveBlobis equivalent toerr == nil, which is both redundant and makes the interface unnecessarily difficult to use for the typical case where the caller wants to abort on an unexpected error, and then decide based on haveBlob:Insted, define the interface to be
(true, nil): blob exists(false, nil): blob does not exist or unknown(false,non-nil): unexpected errorwhich simplifies the “abort” conditional to a simple
err != nil.A possible alternative would be to eliminate the
haveBlobbool instead, but that still requires two-clause checks for aborting, and semantically a blob not being present is not an error, it is a succesfully obtained return value.