-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from dc0d/test-coverage
add code quality & test coverage check
- Loading branch information
Showing
4 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
[![PkgGoDev](https://pkg.go.dev/badge/dc0d/wrapperr)](https://pkg.go.dev/github.com/dc0d/wrapperr) | ||
[![PkgGoDev](https://pkg.go.dev/badge/dc0d/wrapperr)](https://pkg.go.dev/github.com/dc0d/wrapperr) [![Go Report Card](https://goreportcard.com/badge/github.com/dc0d/wrapperr)](https://goreportcard.com/report/github.com/dc0d/wrapperr) [![Maintainability](https://api.codeclimate.com/v1/badges/c0fdd128cafcb6ce0c52/maintainability)](https://codeclimate.com/github/dc0d/wrapperr/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/c0fdd128cafcb6ce0c52/test_coverage)](https://codeclimate.com/github/dc0d/wrapperr/test_coverage) | ||
|
||
# wrapperr | ||
|
||
> a pick at _where the logging happens_ vs _where the error happened_ in Go | ||
_Where_ did that error happen down the call chain? | ||
|
||
Many Go modules for logging provide the option to log where the methods of the logger are called. For example the `logger.Error(someError)` could be called inside a file named _service.go_, from a function named `gitrepo.com/user/module/service-pkg/Connect(...)`. | ||
> Right at the bottom! | ||
That's useful information. | ||
<div align="center"> | ||
<img src="./images/github_com_dc0d_wrapperr.png" width="80%" alt="https://github.com/dc0d/wrapperr"> | ||
</div> | ||
|
||
But **where** the actual error - `someError` - is coming from? | ||
<br /> | ||
|
||
This library provides a utility for enhancing the error with information about the call stack. Which is very helpful especially while working on legacy code-bases. | ||
All you need to do is, instead of: | ||
|
||
Also the root cause error can be accessed using the standard `errors.Unwrap(error)` function at any step. | ||
```go | ||
return nil, err | ||
``` | ||
|
||
Do: | ||
|
||
```go | ||
return nil, wrapperr.WithStack(err) | ||
``` | ||
|
||
Also, it is possible to annotate the stack in the middle: | ||
|
||
<div align="center"> | ||
<img src="./images/github_com_dc0d_wrapperr_annotate.png" width="80%" alt="https://github.com/dc0d/wrapperr"> | ||
</div> | ||
|
||
<br /> | ||
|
||
And to get the original error, just used the standard `errors.Unwrap(error)` function from built-in `errors` package. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.