Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace error type assertions with errors.As in DefaultFormattingStrategy #353

Merged
merged 2 commits into from
Apr 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions strategy/exception/default_exception_formatting_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package exception
import (
"bytes"
"crypto/rand"
goerrors "errors"
"fmt"
"runtime"
"strings"
Expand Down Expand Up @@ -115,7 +116,8 @@ func (dEFS *DefaultFormattingStrategy) Panicf(formatString string, args ...inter
// ExceptionFromError takes an error and returns value of Exception
func (dEFS *DefaultFormattingStrategy) ExceptionFromError(err error) Exception {
var isRemote bool
if reqErr, ok := err.(awserr.RequestFailure); ok {
var reqErr awserr.RequestFailure
bhautikpip marked this conversation as resolved.
Show resolved Hide resolved
if goerrors.As(err, &reqErr) {
// A service error occurs
if reqErr.RequestID() != "" {
isRemote = true
Expand All @@ -133,22 +135,25 @@ func (dEFS *DefaultFormattingStrategy) ExceptionFromError(err error) Exception {
Remote: isRemote,
}

if err, ok := err.(*XRayError); ok {
e.Type = err.Type
xRayErr := &XRayError{}
if goerrors.As(err, &xRayErr) {
bhautikpip marked this conversation as resolved.
Show resolved Hide resolved
e.Type = xRayErr.Type
}

var s []uintptr

// This is our publicly supported interface for passing along stack traces
if err, ok := err.(StackTracer); ok {
s = err.StackTrace()
var st StackTracer
if goerrors.As(err, &st) {
s = st.StackTrace()
}

// We also accept github.com/pkg/errors style stack traces for ease of use
if err, ok := err.(interface {
var est interface {
StackTrace() errors.StackTrace
}); ok {
for _, frame := range err.StackTrace() {
}
if goerrors.As(err, &est) {
for _, frame := range est.StackTrace() {
s = append(s, uintptr(frame))
}
}
Expand Down