https://github.com/qawatake/dwrap
Linter: dwrap forces every public function to begin with an deferring call of a error wrapping function like derrors.Wrap.
https://github.com/qawatake/dwrap
go golang linter staticanalysis
Last synced: 11 months ago
JSON representation
Linter: dwrap forces every public function to begin with an deferring call of a error wrapping function like derrors.Wrap.
- Host: GitHub
- URL: https://github.com/qawatake/dwrap
- Owner: qawatake
- License: mit
- Created: 2023-10-21T06:08:28.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-29T04:38:01.000Z (over 2 years ago)
- Last Synced: 2025-02-09T07:41:13.532Z (about 1 year ago)
- Topics: go, golang, linter, staticanalysis
- Language: Go
- Homepage: https://pkg.go.dev/github.com/qawatake/dwrap
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dwrap
[](https://pkg.go.dev/github.com/qawatake/dwrap)
[](https://github.com/qawatake/dwrap/actions/workflows/test.yaml)
[](https://codecov.io/gh/qawatake/dwrap)
Linter `dwrap` forces every public function to begin with a deferring call of an error wrapping function like [derrors.Wrap](https://github.com/golang/pkgsite/blob/5f0513d53cff8382238b5f8c78e8317d2b4ad06d/internal/derrors/derrors.go#L240).
By using `dwrap`, you can prevent functions from returning without wrapping errors.
```go
func Good() (err error) {
defer derrors.Wrap(&err, "Good")
doStuff()
return nil
}
func Bad() error { // <- should call defer derrors.Wrap fist.
doOtherStuff()
return nil
}
//lint:ignore dwrap this is because ...
func Ignored() error {
doOtherStuff()
return nil
}
```
## How to use
Build your `dwrap` binary by writing `main.go` like below.
```go
package main
import (
"github.com/qawatake/dwrap"
"golang.org/x/tools/go/analysis/unitchecker"
)
func main() {
unitchecker.Main(
dwrap.NewAnalyzer("your/derrors/pkg", "Wrap"),
)
}
```
Then, run `go vet` with your `dwrap` binary.
```sh
go vet -vettool=/path/to/your/dwrap ./...
```