https://github.com/akihirosuda/go-wrap-to-percent-w
convert `Wrap(err, "foo")` to `Errorf("foo: %w", err)`
https://github.com/akihirosuda/go-wrap-to-percent-w
golang
Last synced: 4 months ago
JSON representation
convert `Wrap(err, "foo")` to `Errorf("foo: %w", err)`
- Host: GitHub
- URL: https://github.com/akihirosuda/go-wrap-to-percent-w
- Owner: AkihiroSuda
- License: apache-2.0
- Created: 2021-08-21T23:57:27.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-08-22T01:14:27.000Z (about 4 years ago)
- Last Synced: 2024-10-18T07:34:45.078Z (about 1 year ago)
- Topics: golang
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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")`](https://pkg.go.dev/github.com/pkg/errors#Wrap)
to modern Go-native [`fmt.Errorf("foo: %w", err)`](https://pkg.go.dev/fmt#Errorf)
introduced in [Go 1.13](https://go.dev/blog/go1.13-errors).
## 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
```console
go get github.com/AkihiroSuda/go-wrap-to-percent-w
```
## Usage
:warning: Backup your data before conversion
```console
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 (`./...`)