Skip to content

AkihiroSuda/go-wrap-to-percent-w

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-wrap-to-percent-w: convert Wrap(err, "foo") to Errorf("foo: %w", err)

go-wrap-to-percent-w converts legacy github.com/pkg/errors.Wrap(err, "foo") to modern Go-native fmt.Errorf("foo: %w", err) introduced in Go 1.13.

Conversion rule

Input Output
errors.Wrap(err, "foo") fmt.Errorf("foo: %w", err)
errors.Wrapf(err, "foo %s %d", s, d) fmt.Errorf("foo %s %d: %w", s, d, err)
errors.Errorf("foo %s %d", s,d) fmt.Errorf("foo %s %d", s, d)
import "github.com/pkg/errors" import "errors"

Unsupported functions and types: Cause, WithMessage, WithMessagef, WithStack, Frame, StackTrace

Install

go get github.com/AkihiroSuda/go-wrap-to-percent-w

Usage

⚠️ Backup your data before conversion

go-wrap-to-percent-w -w *.go

Flags:

  • -w: write result to (source) file instead of stdout (Default: false)
  • -gofmt: run gofmt after conversion (Default: true)

TODO: support specifying package names (./...)

About

convert `Wrap(err, "foo")` to `Errorf("foo: %w", err)`

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages