Skip to content

Commit

Permalink
Merge pull request #12 from dc0d/test-coverage
Browse files Browse the repository at this point in the history
add code quality & test coverage check
  • Loading branch information
dc0d authored Jan 6, 2021
2 parents 507218a + 01c10de commit 3b737b0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,21 @@ jobs:
uses: golangci/golangci-lint-action@v2
with:
version: v1.29

- name: Test Reporter 1
run: |
export GIT_COMMIT_SHA="${GITHUB_SHA}"
export GIT_BRANCH="${GITHUB_REF/refs\/heads\//}"
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build
- name: Test With Coverage
run: |
go test -count=1 -timeout 60s -p 1 -coverprofile c.out -coverpkg=./... ./...
- name: Test Reporter 2
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
run: |
./cc-test-reporter after-build --prefix github.com/dc0d/wrapperr
34 changes: 27 additions & 7 deletions README.md
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.
Binary file added images/github_com_dc0d_wrapperr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/github_com_dc0d_wrapperr_annotate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3b737b0

Please sign in to comment.