From b68c019e93c524d488548fa331db2663fd697ddb Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Tue, 19 May 2020 15:50:57 +0200 Subject: [PATCH] Implement ErrParsingFailed error Signed-off-by: Ulysses Souza --- azure/aci.go | 7 ++++--- azure/convert/volume.go | 15 +++++++++------ errdefs/errors.go | 2 ++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/azure/aci.go b/azure/aci.go index d9fd89732..9d2cf58fd 100644 --- a/azure/aci.go +++ b/azure/aci.go @@ -9,8 +9,6 @@ import ( "strings" "time" - "github.com/docker/api/azure/login" - "github.com/Azure/azure-sdk-for-go/profiles/2019-03-01/resources/mgmt/resources" "github.com/Azure/azure-sdk-for-go/profiles/preview/preview/subscription/mgmt/subscription" "github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance" @@ -21,6 +19,9 @@ import ( "github.com/gobwas/ws/wsutil" "github.com/pkg/errors" + "github.com/docker/api/azure/login" + "github.com/docker/api/errdefs" + "github.com/docker/api/context/store" ) @@ -261,7 +262,7 @@ func getSubscriptionsClient() (subscription.SubscriptionsClient, error) { subc := subscription.NewSubscriptionsClient() authorizer, err := login.NewAuthorizerFromLogin() if err != nil { - return subscription.SubscriptionsClient{}, err + return subscription.SubscriptionsClient{}, errors.Wrap(errdefs.ErrLoginFailed, err.Error()) } subc.Authorizer = authorizer return subc, nil diff --git a/azure/convert/volume.go b/azure/convert/volume.go index 0368aa374..24d630531 100644 --- a/azure/convert/volume.go +++ b/azure/convert/volume.go @@ -1,13 +1,16 @@ package convert import ( - "errors" "fmt" "net/url" "path/filepath" "strings" + "github.com/pkg/errors" + "github.com/compose-spec/compose-go/types" + + "github.com/docker/api/errdefs" ) // GetRunVolumes return volume configurations for a project and a single service @@ -74,7 +77,7 @@ func volumeURL(pathURL string) (*url.URL, error) { count := strings.Count(pathURL, ":") if count > 2 { - return nil, fmt.Errorf("unable to parse volume mount %q", pathURL) + return nil, errors.Wrap(errdefs.ErrParsingFailed, fmt.Sprintf("unable to parse volume mount %q", pathURL)) } if count == 2 { tokens := strings.Split(pathURL, ":") @@ -86,20 +89,20 @@ func volumeURL(pathURL string) (*url.URL, error) { func (v *volumeInput) parse(name string, s string) error { volumeURL, err := volumeURL(s) if err != nil { - return fmt.Errorf("volume specification %q could not be parsed %q", s, err) + return errors.Wrap(errdefs.ErrParsingFailed, fmt.Sprintf("volume specification %q could not be parsed %q", s, err)) } v.username = volumeURL.User.Username() if v.username == "" { - return fmt.Errorf("volume specification %q does not include a storage username", v) + return errors.Wrap(errdefs.ErrParsingFailed, fmt.Sprintf("volume specification %q does not include a storage username", v)) } key, ok := volumeURL.User.Password() if !ok || key == "" { - return fmt.Errorf("volume specification %q does not include a storage key", v) + return errors.Wrap(errdefs.ErrParsingFailed, fmt.Sprintf("volume specification %q does not include a storage key", v)) } v.key = unescapeKey(key) v.share = volumeURL.Host if v.share == "" { - return fmt.Errorf("volume specification %q does not include a storage file share", v) + return errors.Wrap(errdefs.ErrParsingFailed, fmt.Sprintf("volume specification %q does not include a storage file share", v)) } v.name = name v.target = volumeURL.Path diff --git a/errdefs/errors.go b/errdefs/errors.go index be64d2114..6fae1e8f3 100644 --- a/errdefs/errors.go +++ b/errdefs/errors.go @@ -45,6 +45,8 @@ var ( // ErrNotImplemented is returned when a backend doesn't implement // an action ErrNotImplemented = errors.New("not implemented") + // ErrParsingFailed + ErrParsingFailed = errors.New("parsing failed") ) // IsNotFoundError returns true if the unwrapped error is ErrNotFound