Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
fix: replace error messages with more user friendly versions (#446)
Browse files Browse the repository at this point in the history
Closes #422
Closes #439
  • Loading branch information
technosophos authored Nov 19, 2018
1 parent 6921118 commit 00d3d38
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
14 changes: 5 additions & 9 deletions cmd/duffle/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ Verifying and --insecure:
func bundleFileOrArg2(args []string, bun string, w io.Writer, insecure bool) (string, error) {
switch {
case len(args) < 1:
return "", errors.New("This command requires at least one argument: NAME (name for the installation). It also requires a BUNDLE (CNAB bundle name) or file (using -f)\nValid inputs:\n\t$ duffle install NAME BUNDLE\n\t$ duffle install NAME -f path-to-bundle.json")
return "", errors.New("this command requires at least one argument: NAME (name for the installation). It also requires a BUNDLE (CNAB bundle name) or file (using -f)\nValid inputs:\n\t$ duffle install NAME BUNDLE\n\t$ duffle install NAME -f path-to-bundle.json")
case len(args) == 2 && bun != "":
return "", errors.New("please use either -f or specify a BUNDLE, but not both")
case len(args) < 2 && bun == "":
Expand All @@ -183,11 +183,7 @@ func optBundleFileOrArg2(args []string, bun string, w io.Writer, insecure bool)
// No bundle provided
return "", nil
case len(args) == 2:
var err error
bun, err = pullBundle(args[1], insecure)
if err != nil {
return "", err
}
return pullBundle(args[1], insecure)
}
return bun, nil
}
Expand All @@ -202,7 +198,7 @@ func loadOrPullBundle(bun string, insecure bool) (string, error) {
// read the bundle reference from repositories.json
index, err := repo.LoadIndex(home.Repositories())
if err != nil {
return "", fmt.Errorf("cannot open %s: %v\n try running duffle init first", home.Repositories(), err)
return "", fmt.Errorf("cannot open %s: %v", home.Repositories(), err)
}

digest, err := index.Get(ref.Name(), ref.Tag())
Expand Down Expand Up @@ -237,7 +233,7 @@ func overrides(overrides []string, paramDefs map[string]bundle.ParameterDefiniti
var err error
res[pair[0]], err = def.ConvertValue(pair[1])
if err != nil {
return res, fmt.Errorf("can't use %s as value of %s: %s", pair[1], pair[0], err)
return res, fmt.Errorf("cannot use %s as value of %s: %s", pair[1], pair[0], err)
}
}
return res, nil
Expand Down Expand Up @@ -288,7 +284,7 @@ func calculateParamValues(bun *bundle.Bundle, valuesFile string, setParams, setF
}
content, err := ioutil.ReadFile(parts[1])
if err != nil {
return vals, fmt.Errorf("error while reading file %q: %s", parts[1], err)
return vals, fmt.Errorf("could not read file %q: %s", parts[1], err)
}
vals[parts[0]] = string(content)
}
Expand Down
21 changes: 18 additions & 3 deletions cmd/duffle/pull.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -102,7 +103,7 @@ func getLoader(insecure bool) (loader.Loader, error) {
} else {
kr, err := loadVerifyingKeyRings(homePath())
if err != nil {
return nil, err
return nil, fmt.Errorf("cannot securely load bundle: %s", err)
}
load = loader.NewSecureLoader(kr)
}
Expand All @@ -123,7 +124,7 @@ func getReference(bundleName string) (reference.NamedTagged, error) {
}
normalizedRef, err := reference.ParseNormalizedNamed(name)
if err != nil {
return nil, fmt.Errorf("failed to parse image name: %s: %v", name, err)
return nil, fmt.Errorf("%q is not a valid bundle name: %v", name, err)
}
if reference.IsNameOnly(normalizedRef) {
ref, err = reference.WithTag(normalizedRef, "latest")
Expand Down Expand Up @@ -167,5 +168,19 @@ func loadBundle(bundleFile string, insecure bool) (*bundle.Bundle, error) {
if err != nil {
return nil, err
}
return l.Load(bundleFile)
// Issue #439: Errors that come back from the loader can be
// pretty opaque.
var bun *bundle.Bundle
if bun, err := l.Load(bundleFile); err != nil {
if err.Error() == "no signature block in data" {
return bun, errors.New("bundle is not signed")
}
// Dear Go, Y U NO TERNARY, kthxbye
secflag := "secure"
if insecure {
secflag = "insecure"
}
return bun, fmt.Errorf("cannot load %s bundle: %s", secflag, err)
}
return bun, nil
}
4 changes: 2 additions & 2 deletions pkg/reference/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type normalizedNamed interface {
// use ParseAnyReference.
func ParseNormalizedNamed(s string) (Named, error) {
if ok := anchoredIdentifierRegexp.MatchString(s); ok {
return nil, fmt.Errorf("invalid repository name (%s), cannot specify 64-byte hexadecimal strings", s)
return nil, fmt.Errorf("repository name (%s) cannot be a 64-byte hexadecimal strings", s)
}
domain, remainder := splitDockerDomain(s)
var remoteName string
Expand All @@ -40,7 +40,7 @@ func ParseNormalizedNamed(s string) (Named, error) {
remoteName = remainder
}
if strings.ToLower(remoteName) != remoteName {
return nil, errors.New("invalid reference format: repository name must be lowercase")
return nil, errors.New("in a reference name, the repository part must be lowercase")
}

ref, err := Parse(domain + "/" + remainder)
Expand Down

0 comments on commit 00d3d38

Please sign in to comment.