diff --git a/go.mod b/go.mod index 728876b..a3b1f9b 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/gonvenience/neat v1.3.12 github.com/gonvenience/term v1.0.2 github.com/gonvenience/text v1.0.7 - github.com/gonvenience/wrap v1.1.2 + github.com/gonvenience/wrap v1.2.0 github.com/gonvenience/ytbx v1.4.4 github.com/lucasb-eyer/go-colorful v1.2.0 github.com/mitchellh/hashstructure v1.1.0 diff --git a/go.sum b/go.sum index 11c586b..42a08c6 100644 --- a/go.sum +++ b/go.sum @@ -20,6 +20,8 @@ github.com/gonvenience/text v1.0.7 h1:YmIqmgTwxnACYCG59DykgMbomwteYyNhAmEUEJtPl1 github.com/gonvenience/text v1.0.7/go.mod h1:OAjH+mohRszffLY6OjgQcUXiSkbrIavooFpfIt1ZwAs= github.com/gonvenience/wrap v1.1.2 h1:xPKxNwL1HCguwyM+HlP/1CIuc9LRd7k8RodLwe9YTZA= github.com/gonvenience/wrap v1.1.2/go.mod h1:GiryBSXoI3BAAhbWD1cZVj7RZmtiu0ERi/6R6eJfslI= +github.com/gonvenience/wrap v1.2.0 h1:CwAoa60QIBVmQn/aUregAbk9FstEr17k9vCYpKF972c= +github.com/gonvenience/wrap v1.2.0/go.mod h1:iNijaTmFD8+ORmNp9iS+dSBcCJrmIwwyoYLUngToGdk= github.com/gonvenience/ytbx v1.4.4 h1:jQopwyaLsVGuwdxSiN4WkXjsEaFNPJ3V4lUj7eyEpzo= github.com/gonvenience/ytbx v1.4.4/go.mod h1:w37+MKCPcCMY/jpPNmEklD4xKqrOAVBO6kIWW2+uI6M= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= diff --git a/internal/cmd/between.go b/internal/cmd/between.go index 6f78035..24f6e37 100644 --- a/internal/cmd/between.go +++ b/internal/cmd/between.go @@ -21,7 +21,8 @@ package cmd import ( - "github.com/gonvenience/wrap" + "fmt" + "github.com/gonvenience/ytbx" "github.com/spf13/cobra" @@ -60,7 +61,7 @@ types are: YAML (http://yaml.org/) and JSON (http://json.org/). from, to, err := ytbx.LoadFiles(fromLocation, toLocation) if err != nil { - return wrap.Errorf(err, "failed to load input files") + return fmt.Errorf("failed to load input files: %w", err) } // If the main change root flag is set, this (re-)sets the individual change roots of the two input files @@ -72,14 +73,14 @@ types are: YAML (http://yaml.org/) and JSON (http://json.org/). // Change root of 'from' input file if change root flag for 'from' is set if betweenCmdSettings.chrootFrom != "" { if err = dyff.ChangeRoot(&from, betweenCmdSettings.chrootFrom, reportOptions.useGoPatchPaths, betweenCmdSettings.translateListToDocuments); err != nil { - return wrap.Errorf(err, "failed to change root of %s to path %s", from.Location, betweenCmdSettings.chrootFrom) + return fmt.Errorf("failed to change root of %s to path %s: %w", from.Location, betweenCmdSettings.chrootFrom, err) } } // Change root of 'to' input file if change root flag for 'to' is set if betweenCmdSettings.chrootTo != "" { if err = dyff.ChangeRoot(&to, betweenCmdSettings.chrootTo, reportOptions.useGoPatchPaths, betweenCmdSettings.translateListToDocuments); err != nil { - return wrap.Errorf(err, "failed to change root of %s to path %s", to.Location, betweenCmdSettings.chrootTo) + return fmt.Errorf("failed to change root of %s to path %s: %w", to.Location, betweenCmdSettings.chrootTo, err) } } @@ -90,7 +91,7 @@ types are: YAML (http://yaml.org/) and JSON (http://json.org/). ) if err != nil { - return wrap.Errorf(err, "failed to compare input files") + return fmt.Errorf("failed to compare input files: %w", err) } if reportOptions.filters != nil { diff --git a/internal/cmd/common.go b/internal/cmd/common.go index 01652f3..d28b069 100644 --- a/internal/cmd/common.go +++ b/internal/cmd/common.go @@ -30,7 +30,6 @@ import ( "github.com/gonvenience/bunt" "github.com/gonvenience/neat" - "github.com/gonvenience/wrap" "github.com/gonvenience/ytbx" "github.com/spf13/cobra" yamlv3 "gopkg.in/yaml.v3" @@ -118,7 +117,7 @@ func humanReadableFilename(filename string) string { // stored in the provided input file to the standard output func (w *OutputWriter) WriteToStdout(filename string) error { if err := w.write(os.Stdout, filename); err != nil { - return wrap.Error(err, bunt.Sprint("failed to write output to _*stdout*_")) + return bunt.Errorf("failed to write output to _*stdout*_: %w", err) } return nil @@ -133,13 +132,13 @@ func (w *OutputWriter) WriteInplace(filename string) error { // Force plain mode to make sure there are no ANSI sequences w.PlainMode = true if err := w.write(bufWriter, filename); err != nil { - return wrap.Errorf(err, "failed to write output to %s", humanReadableFilename(filename)) + return fmt.Errorf("failed to write output to %s: %w", humanReadableFilename(filename), err) } // Write the buffered output to the provided input file (override in place) bufWriter.Flush() if err := os.WriteFile(filename, buf.Bytes(), 0644); err != nil { - return wrap.Errorf(err, "failed to overwrite %s in place", humanReadableFilename(filename)) + return fmt.Errorf("failed to overwrite %s in place: %w", humanReadableFilename(filename), err) } return nil @@ -148,7 +147,7 @@ func (w *OutputWriter) WriteInplace(filename string) error { func (w *OutputWriter) write(writer io.Writer, filename string) error { inputFile, err := ytbx.LoadFile(filename) if err != nil { - return wrap.Errorf(err, "failed to load input from %s", humanReadableFilename(filename)) + return fmt.Errorf("failed to load input from %s: %w", humanReadableFilename(filename), err) } for _, document := range inputFile.Documents { @@ -215,14 +214,11 @@ func writeReport(cmd *cobra.Command, report dyff.Report) error { } default: - return wrap.Errorf( - fmt.Errorf(cmd.UsageString()), - "unknown output style %s", reportOptions.style, - ) + return fmt.Errorf("unknown output style %s: %w", reportOptions.style, fmt.Errorf(cmd.UsageString())) } if err := reportWriter.WriteReport(os.Stdout); err != nil { - return wrap.Errorf(err, "failed to print report") + return fmt.Errorf("failed to print report: %w", err) } // If configured, make sure `dyff` exists with an exit status diff --git a/internal/cmd/json.go b/internal/cmd/json.go index 2742269..67e0b6d 100644 --- a/internal/cmd/json.go +++ b/internal/cmd/json.go @@ -57,10 +57,7 @@ Converts input document into JSON format while preserving the order of all keys. var errors []error for _, filename := range args { if ytbx.IsStdin(filename) && jsonCmdSettings.inplace { - return wrap.Error( - fmt.Errorf("cannot use in-place flag in combination with input from STDIN"), - "incompatible flags", - ) + return fmt.Errorf("incompatible flags: %w", fmt.Errorf("cannot use in-place flag in combination with input from STDIN")) } if jsonCmdSettings.inplace { diff --git a/internal/cmd/lastApplied.go b/internal/cmd/lastApplied.go index 4a02718..e5a9860 100644 --- a/internal/cmd/lastApplied.go +++ b/internal/cmd/lastApplied.go @@ -23,7 +23,6 @@ package cmd import ( "fmt" - "github.com/gonvenience/wrap" "github.com/gonvenience/ytbx" "github.com/spf13/cobra" yamlv3 "gopkg.in/yaml.v3" @@ -61,7 +60,7 @@ to compare it against the current configuration. report, err := dyff.CompareInputFiles(lastConfiguration, inputFile, dyff.IgnoreOrderChanges(reportOptions.ignoreOrderChanges)) if err != nil { - return wrap.Errorf(err, "failed to compare input files") + return fmt.Errorf("failed to compare input files: %w", err) } return writeReport(cmd, report) diff --git a/internal/cmd/yaml.go b/internal/cmd/yaml.go index 475d0e5..60e1863 100644 --- a/internal/cmd/yaml.go +++ b/internal/cmd/yaml.go @@ -21,6 +21,8 @@ package cmd import ( + "fmt" + "github.com/gonvenience/bunt" "github.com/gonvenience/wrap" "github.com/gonvenience/ytbx" @@ -57,10 +59,7 @@ Converts input document into YAML format while preserving the order of all keys. var errors []error for _, filename := range args { if ytbx.IsStdin(filename) && yamlCmdSettings.inplace { - return wrap.Error( - bunt.Errorf("cannot use in-place flag in combination with input from _*stdin*_"), - "incompatible flags", - ) + return fmt.Errorf("incompatible flags: %w", bunt.Errorf("cannot use in-place flag in combination with input from _*stdin*_")) } if yamlCmdSettings.inplace { diff --git a/pkg/dyff/core.go b/pkg/dyff/core.go index 9e440b7..b4fd07a 100644 --- a/pkg/dyff/core.go +++ b/pkg/dyff/core.go @@ -27,7 +27,6 @@ import ( "github.com/gonvenience/bunt" "github.com/gonvenience/text" - "github.com/gonvenience/wrap" "github.com/gonvenience/ytbx" "github.com/mitchellh/hashstructure" yamlv3 "gopkg.in/yaml.v3" @@ -961,7 +960,7 @@ func (compare *compare) calcNodeHash(node *yamlv3.Node) (hash uint64) { } if err != nil { - panic(wrap.Errorf(err, "failed to calculate hash of %#v", node.Value)) + panic(fmt.Errorf("failed to calculate hash of %#v: %w", node.Value, err)) } return hash