Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
issue #151: change Recover logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Aug 15, 2018
1 parent 2b6f940 commit c5aa497
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Code Quality](https://scrutinizer-ci.com/g/kamilsk/form-api/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/kamilsk/form-api/?branch=master)
[![Go version](https://img.shields.io/badge/Go-%3E%3D%201.9.2-green.svg)](https://travis-ci.org/kamilsk/form-api)
[![Code Coverage](https://scrutinizer-ci.com/g/kamilsk/form-api/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/kamilsk/form-api/?branch=master)
[![Research](https://img.shields.io/badge/research-in%20progress-yellow.svg)](../../tree/research)
[![Research](https://img.shields.io/badge/research-in%20progress-yellow.svg)](../../tree/research/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

## Roadmap
Expand Down
Empty file removed pkg/draft/.gitkeep
Empty file.
14 changes: 9 additions & 5 deletions pkg/errors/wrapper.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package errors

import (
"fmt"

core "errors"

"github.com/pkg/errors"
Expand All @@ -16,11 +14,12 @@ func Errorf(format string, args ...interface{}) error {
// Recover recovers execution flow and sets error to the passed error pointer.
func Recover(err *error) {
if r := recover(); r != nil {
if e, is := r.(error); is {
switch e := (r).(type) {
case error:
*err = e
return
default:
*err = Errorf("panic `%#v` handled", r)
}
*err = fmt.Errorf("%v", r)
}
}

Expand All @@ -47,6 +46,11 @@ func WithMessage(err error, message string) error {
return errors.WithMessage(err, message)
}

// WithStack is a proxy for `github.com/pkg/errors.WithStack`.
func WithStack(err error) error {
return errors.WithStack(err)
}

// Wrapf is a proxy for `github.com/pkg/errors.Wrapf`.
func Wrapf(err error, format string, args ...interface{}) error {
return errors.Wrapf(err, format, args...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/errors/wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestRecover(t *testing.T) {
}{
{"error with stack trace", func() { panic(errors.Errorf("panic")) }, assert.NotEmpty},
{"error without stack trace", func() { panic(errors.Simple("panic")) }, assert.Empty},
{"not error panic", func() { panic("panic") }, assert.Empty},
{"not error panic", func() { panic("panic") }, assert.NotEmpty},
}
for _, test := range tests {
tc := test
Expand Down

0 comments on commit c5aa497

Please sign in to comment.