-
Notifications
You must be signed in to change notification settings - Fork 23
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 #64 from wheniwork/master
Allow full customization of error unwrapping and stack tracing (and support Unwrap automatically)
- Loading branch information
Showing
9 changed files
with
365 additions
and
102 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
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,3 +1,5 @@ | ||
module github.com/rollbar/rollbar-go/errors | ||
|
||
go 1.13 | ||
|
||
require github.com/pkg/errors v0.8.1 |
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 +1,3 @@ | ||
module github.com/rollbar/rollbar-go | ||
|
||
go 1.13 |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package rollbar_test | ||
|
||
import ( | ||
"runtime" | ||
|
||
"github.com/rollbar/rollbar-go" | ||
) | ||
|
||
type CustomTraceError struct { | ||
error | ||
trace []runtime.Frame | ||
} | ||
|
||
func (e CustomTraceError) GetTrace() []runtime.Frame { | ||
return e.trace | ||
} | ||
|
||
func ExampleSetStackTracer() { | ||
rollbar.SetStackTracer(func(err error) ([]runtime.Frame, bool) { | ||
// preserve the default behavior for other types of errors | ||
if trace, ok := rollbar.DefaultStackTracer(err); ok { | ||
return trace, ok | ||
} | ||
|
||
if cerr, ok := err.(CustomTraceError); ok { | ||
return cerr.GetTrace(), true | ||
} | ||
|
||
return nil, false | ||
}) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package rollbar_test | ||
|
||
import "github.com/rollbar/rollbar-go" | ||
|
||
type CustomWrappingError struct { | ||
error | ||
wrapped error | ||
} | ||
|
||
func (e CustomWrappingError) GetWrappedError() error { | ||
return e.wrapped | ||
} | ||
|
||
func ExampleSetUnwrapper() { | ||
rollbar.SetUnwrapper(func(err error) error { | ||
// preserve the default behavior for other types of errors | ||
if unwrapped := rollbar.DefaultUnwrapper(err); unwrapped != nil { | ||
return unwrapped | ||
} | ||
|
||
if ex, ok := err.(CustomWrappingError); ok { | ||
return ex.GetWrappedError() | ||
} | ||
|
||
return nil | ||
}) | ||
} |
Oops, something went wrong.