Skip to content

Commit

Permalink
Remove usage of deprecated wrap.Error function
Browse files Browse the repository at this point in the history
Use `fmt.Errorf` or `bunt.Errorf` instead.
  • Loading branch information
HeavyWombat committed Oct 15, 2023
1 parent bdf15b9 commit 6d63425
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -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=
Expand Down
11 changes: 6 additions & 5 deletions internal/cmd/between.go
Expand Up @@ -21,7 +21,8 @@
package cmd

import (
"github.com/gonvenience/wrap"
"fmt"

"github.com/gonvenience/ytbx"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}

Expand All @@ -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 {
Expand Down
16 changes: 6 additions & 10 deletions internal/cmd/common.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions internal/cmd/json.go
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions internal/cmd/lastApplied.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions internal/cmd/yaml.go
Expand Up @@ -21,6 +21,8 @@
package cmd

import (
"fmt"

"github.com/gonvenience/bunt"
"github.com/gonvenience/wrap"
"github.com/gonvenience/ytbx"
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions pkg/dyff/core.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6d63425

Please sign in to comment.