-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
This library was created before Go 1.13 where error wrapping was introduced. So, it did not wrap errors, which made error handling at the caller side a bit tricky.
For instance, when opening an unknown bucket, the HTTP 404 error was replaced by a custom "Unknown bucket" error.
https://github.com/jacobsa/gcloud/blob/master/gcs/conn.go#L191-L192
case http.StatusNotFound:
err = fmt.Errorf("Unknown bucket %q", b.Name())
This error is hard to be handled by the caller. However, if we wrap the internal http error like this:
case http.StatusNotFound:
err = fmt.Errorf("Unknown bucket %q: %w", b.Name(), err)
On the user side, such error can be casted back to an 404, and properly handled:
if errors.As(err, &apiErr) {
switch apiErr.Code {
case http.StatusNotFound:
return syscall.EINVAL
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels