Procházet zdrojové kódy

Implement ErrParsingFailed error

Signed-off-by: Ulysses Souza <[email protected]>
Ulysses Souza před 5 roky
rodič
revize
b68c019e93
3 změnil soubory, kde provedl 15 přidání a 9 odebrání
  1. 4 3
      azure/aci.go
  2. 9 6
      azure/convert/volume.go
  3. 2 0
      errdefs/errors.go

+ 4 - 3
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

+ 9 - 6
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

+ 2 - 0
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