From b03a18572363560845439eec041502014da85128 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Fri, 24 Mar 2017 10:43:28 -0400 Subject: [PATCH] Cleanup compose convert error messages. Signed-off-by: Daniel Nephin --- cli/compose/convert/service.go | 15 +++++++++------ cli/compose/convert/volume.go | 2 +- cli/compose/convert/volume_test.go | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 497dbe004f..8e31cbe8fb 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -14,6 +14,7 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/opts" runconfigopts "github.com/docker/docker/runconfig/opts" + "github.com/pkg/errors" ) const defaultNetwork = "default" @@ -35,11 +36,11 @@ func Services( secrets, err := convertServiceSecrets(client, namespace, service.Secrets, config.Secrets) if err != nil { - return nil, err + return nil, errors.Wrapf(err, "service %s", service.Name) } serviceSpec, err := convertService(namespace, service, networks, volumes, secrets) if err != nil { - return nil, err + return nil, errors.Wrapf(err, "service %s", service.Name) } result[service.Name] = serviceSpec } @@ -68,7 +69,6 @@ func convertService( mounts, err := Volumes(service.Volumes, volumes, namespace) if err != nil { - // TODO: better error message (include service name) return swarm.ServiceSpec{}, err } @@ -167,8 +167,7 @@ func convertServiceNetworks( for networkName, network := range networks { networkConfig, ok := networkConfigs[networkName] if !ok && networkName != defaultNetwork { - return []swarm.NetworkAttachmentConfig{}, fmt.Errorf( - "service %q references network %q, which is not declared", name, networkName) + return nil, errors.Errorf("undefined network %q", networkName) } var aliases []string if network != nil { @@ -202,8 +201,12 @@ func convertServiceSecrets( target = secret.Source } + secretSpec, exists := secretSpecs[secret.Source] + if !exists { + return nil, errors.Errorf("undefined secret %q", secret.Source) + } + source := namespace.Scope(secret.Source) - secretSpec := secretSpecs[secret.Source] if secretSpec.External.External { source = secretSpec.External.Name } diff --git a/cli/compose/convert/volume.go b/cli/compose/convert/volume.go index 682b44377a..d6b14283ad 100644 --- a/cli/compose/convert/volume.go +++ b/cli/compose/convert/volume.go @@ -57,7 +57,7 @@ func convertVolumeToMount( stackVolume, exists := stackVolumes[volume.Source] if !exists { - return result, errors.Errorf("undefined volume: %s", volume.Source) + return result, errors.Errorf("undefined volume %q", volume.Source) } result.Source = namespace.Scope(volume.Source) diff --git a/cli/compose/convert/volume_test.go b/cli/compose/convert/volume_test.go index 705f03f404..73d642e5fe 100644 --- a/cli/compose/convert/volume_test.go +++ b/cli/compose/convert/volume_test.go @@ -188,5 +188,5 @@ func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) { ReadOnly: true, } _, err := convertVolumeToMount(config, volumes{}, namespace) - assert.Error(t, err, "undefined volume: unknown") + assert.Error(t, err, "undefined volume \"unknown\"") }