Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 7 days 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 (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-29T04:38:01.000Z (about 1 year ago)
- Last Synced: 2024-10-29T12:56:12.577Z (about 2 months 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
[![Go Reference](https://pkg.go.dev/badge/github.com/qawatake/dwrap.svg)](https://pkg.go.dev/github.com/qawatake/dwrap)
[![test](https://github.com/qawatake/dwrap/actions/workflows/test.yaml/badge.svg)](https://github.com/qawatake/dwrap/actions/workflows/test.yaml)
[![codecov](https://codecov.io/gh/qawatake/dwrap/graph/badge.svg?token=er2K6likVZ)](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 mainimport (
"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 ./...
```