Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of deprecated wrap.Error function #324

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@

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 @@
// 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 @@
)

if err != nil {
return wrap.Errorf(err, "failed to compare input files")
return fmt.Errorf("failed to compare input files: %w", err)

Check warning on line 94 in internal/cmd/between.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/between.go#L94

Added line #L94 was not covered by tests
}

if reportOptions.filters != nil {
Expand Down
16 changes: 6 additions & 10 deletions internal/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

"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 @@
// 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)

Check warning on line 120 in internal/cmd/common.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/common.go#L120

Added line #L120 was not covered by tests
}

return nil
Expand All @@ -133,13 +132,13 @@
// 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)

Check warning on line 135 in internal/cmd/common.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/common.go#L135

Added line #L135 was not covered by tests
}

// 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)

Check warning on line 141 in internal/cmd/common.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/common.go#L141

Added line #L141 was not covered by tests
}

return nil
Expand All @@ -148,7 +147,7 @@
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)

Check warning on line 150 in internal/cmd/common.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/common.go#L150

Added line #L150 was not covered by tests
}

for _, document := range inputFile.Documents {
Expand Down Expand Up @@ -215,14 +214,11 @@
}

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)

Check warning on line 221 in internal/cmd/common.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/common.go#L221

Added line #L221 was not covered by tests
}

// If configured, make sure `dyff` exists with an exit status
Expand Down
5 changes: 1 addition & 4 deletions internal/cmd/json.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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 @@

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)

Check warning on line 63 in internal/cmd/lastApplied.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/lastApplied.go#L63

Added line #L63 was not covered by tests
}

return writeReport(cmd, report)
Expand Down
7 changes: 3 additions & 4 deletions internal/cmd/yaml.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

"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 @@
}

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))

Check warning on line 963 in pkg/dyff/core.go

View check run for this annotation

Codecov / codecov/patch

pkg/dyff/core.go#L963

Added line #L963 was not covered by tests
}

return hash
Expand Down
Loading