From afbd9fef7f192db105df559b536ddea12ff34358 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 7 Aug 2020 16:05:08 +0200 Subject: [PATCH] Replace error concat with wrapping Signed-off-by: Knut Ahlers --- assets.go | 4 ++-- go.mod | 1 + go.sum | 2 ++ main.go | 26 +++++++++++++------------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/assets.go b/assets.go index 61a09d5..8e3be82 100644 --- a/assets.go +++ b/assets.go @@ -112,8 +112,8 @@ func bindataAssetsGitchangereleaseyaml() (*asset, error) { name: "assets/git_changerelease.yaml", size: 834, md5checksum: "", - mode: os.FileMode(436), - modTime: time.Unix(1537952066, 0), + mode: os.FileMode(420), + modTime: time.Unix(1537952886, 0), } a := &asset{bytes: bytes, info: info} diff --git a/go.mod b/go.mod index 4bb3f7d..c52edca 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.14 require ( github.com/Luzifer/rconfig/v2 v2.2.1 github.com/mitchellh/go-homedir v1.1.0 + github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.6.0 gopkg.in/yaml.v2 v2.3.0 ) diff --git a/go.sum b/go.sum index 4ca7d7f..5bbf989 100644 --- a/go.sum +++ b/go.sum @@ -6,6 +6,8 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJ github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= diff --git a/main.go b/main.go index 96da70d..3c84fdd 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,6 @@ package main import ( "bytes" - "errors" "fmt" "io/ioutil" "os" @@ -16,6 +15,7 @@ import ( "time" "github.com/mitchellh/go-homedir" + "github.com/pkg/errors" log "github.com/sirupsen/logrus" "github.com/Luzifer/rconfig/v2" @@ -44,7 +44,7 @@ var ( func filenameToGitRoot(fn string) (string, error) { root, err := git(false, "rev-parse", "--show-toplevel") if err != nil { - return "", fmt.Errorf("Unable to fetch root dir: %s", err) + return "", errors.Wrap(err, "Unable to fetch root dir") } return path.Join(root, fn), nil @@ -108,7 +108,7 @@ func loadMatcherRegex(matches []string, bump semVerBump) error { for _, match := range matches { r, err := regexp.Compile(match) if err != nil { - return fmt.Errorf("Unable to parse regex '%s': %s", match, err) + return errors.Wrapf(err, "Unable to parse regex '%s'", match) } matchers[r] = bump } @@ -181,17 +181,17 @@ func main() { func applyTag(stringVersion string) error { var err error if _, err = gitErr("add", cfg.ChangelogFile); err != nil { - return fmt.Errorf("Unable to add changelog file: %s", err) + return errors.Wrap(err, "Unable to add changelog file") } commitMessage, err := quickTemplate("commitMessage", []byte(config.ReleaseCommitMessage), map[string]interface{}{ "Version": stringVersion, }) if err != nil { - return fmt.Errorf("Unable to compile commit message: %s", err) + return errors.Wrap(err, "Unable to compile commit message") } if _, err := gitErr("commit", "-m", string(commitMessage)); err != nil { - return fmt.Errorf("Unable to commit changelog: %s", err) + return errors.Wrap(err, "Unable to commit changelog") } tagType := "-s" // By default use signed tags @@ -200,7 +200,7 @@ func applyTag(stringVersion string) error { } if _, err := gitErr("tag", tagType, "-m", stringVersion, stringVersion); err != nil { - return fmt.Errorf("Unable to tag release: %s", err) + return errors.Wrap(err, "Unable to tag release") } return nil @@ -216,7 +216,7 @@ func fetchGitLogs(since string, fetchAll bool) ([]commit, error) { rawLogs, err := gitErr(logArgs...) if err != nil { - return nil, fmt.Errorf("Unable to read git log entries: %s", err) + return nil, errors.Wrap(err, "Unable to read git log entries") } logs := []commit{} @@ -255,11 +255,11 @@ func renderLog(newVersion *semVer, logs []commit) (*semVer, error) { "OldLog": readChangelog(), }) if err != nil { - return nil, fmt.Errorf("Unable to compile log: %s", err) + return nil, errors.Wrap(err, "Unable to compile log") } if err = ioutil.WriteFile(cfg.ChangelogFile, bytes.TrimSpace(c), 0644); err != nil { - return nil, fmt.Errorf("Unable to write new changelog: %s", err) + return nil, errors.Wrap(err, "Unable to write new changelog") } // Spawning editor @@ -280,7 +280,7 @@ func renderLog(newVersion *semVer, logs []commit) (*semVer, error) { } newVersion, err = parseSemVer(strings.Split(changelog[0], " ")[1]) if err != nil { - return nil, fmt.Errorf("Unable to parse new version from log: %s", err) + return nil, errors.Wrap(err, "Unable to parse new version from log") } return newVersion, nil @@ -290,13 +290,13 @@ func newVersionFromLogs(lastTag string, logs []commit) (*semVer, error) { // Tetermine increase type semVerBumpType, err := selectBumpType(logs) if err != nil { - return nil, fmt.Errorf("Could not determine how to increase the version: %s", err) + return nil, errors.Wrap(err, "Could not determine how to increase the version") } // Generate new version newVersion, err := parseSemVer(lastTag) if err != nil { - return nil, fmt.Errorf("Was unable to parse previous version: %s", err) + return nil, errors.Wrap(err, "Was unable to parse previous version") } if newVersion.PreReleaseInformation == "" && cfg.PreRelease == "" { newVersion.Bump(semVerBumpType)