Skip to content

Commit

Permalink
Merge pull request #23 from goreleaser/errs
Browse files Browse the repository at this point in the history
chore: improving error handling and wrapping
  • Loading branch information
caarlos0 authored Mar 28, 2018
2 parents 368ee0b + db0bbe8 commit 7f4d768
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion deb/deb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestDebFileDoesNotExist(t *testing.T) {
}),
ioutil.Discard,
)
assert.Error(t, err)
assert.EqualError(t, err, "../testdata/whatever.confzzz: file does not exist")
}

func TestDebNoFiles(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions glob/glob.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"

"github.com/mattn/go-zglob"
"github.com/pkg/errors"
)

// longestCommonPrefix returns the longest prefix of all strings the argument
Expand Down Expand Up @@ -43,10 +44,10 @@ func strlcp(a string, b string) string {
func Glob(glob, dst string) (map[string]string, error) {
matches, err := zglob.Glob(glob)
if err != nil {
return nil, err
return nil, errors.Wrap(err, glob)
}
if len(matches) == 0 {
return nil, fmt.Errorf("no files matched by: %s", glob)
return nil, fmt.Errorf("%s: no matching files", glob)
}
files := make(map[string]string)
prefix := longestCommonPrefix(matches)
Expand Down
4 changes: 2 additions & 2 deletions glob/glob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func TestGlob(t *testing.T) {
assert.Equal(t, "/foo/bar/dir_c/test_c.txt", files["testdata/dir_a/dir_c/test_c.txt"])

nilvalue, err := Glob("does/not/exist", "/foo/bar")
assert.Error(t, err)
assert.EqualError(t, err, "does/not/exist: file does not exist")
assert.Nil(t, nilvalue)

nomatches, err := Glob("testdata/nothing*", "/foo/bar")
assert.Nil(t, nomatches)
assert.Error(t, err)
assert.EqualError(t, err, "testdata/nothing*: no matching files")
}

func TestSingleGlob(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion rpm/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (*RPM) Package(info nfpm.Info, w io.Writer) error {
return err
}
if err = createTarGz(info, temps.Folder, temps.Source); err != nil {
return errors.Wrap(err, "failed to create tar.gz")
return err
}
if err = createSpec(info, temps.Spec); err != nil {
return errors.Wrap(err, "failed to create rpm spec file")
Expand Down
27 changes: 27 additions & 0 deletions rpm/rpm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,33 @@ func TestRpmBuildVersion(t *testing.T) {
assert.True(t, v.Path >= 0)
}

func TestRPMFileDoesNotExist(t *testing.T) {
var err = Default.Package(
nfpm.WithDefaults(nfpm.Info{
Name: "foo",
Arch: "amd64",
Depends: []string{
"bash",
},
Description: "Foo does things",
Priority: "extra",
Maintainer: "Carlos A Becker <[email protected]>",
Version: "1.0.0",
Section: "default",
Homepage: "http://carlosbecker.com",
Vendor: "nope",
Files: map[string]string{
"../testdata/": "/usr/local/bin/fake",
},
ConfigFiles: map[string]string{
"../testdata/whatever.confzzz": "/etc/fake/fake.conf",
},
}),
ioutil.Discard,
)
assert.EqualError(t, err, "../testdata/whatever.confzzz: file does not exist")
}

func TestParseRpmbuildVersion(t *testing.T) {
for _, version := range []string{
"RPM-Version 4.14.1",
Expand Down

0 comments on commit 7f4d768

Please sign in to comment.