Skip to content

Commit

Permalink
[#81] refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dwkang committed Dec 6, 2023
1 parent a4e079e commit 40324fe
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func splitName(fullName string) (string, string) {
}

type errorChain struct {
ecs *errorWithCallStack
callstack *errorWithCallStack
exceptionId int64
}

func (span *span) findError(err error) *errorChain {
for _, ec := range span.errorChains {
if ec.ecs.err == err {
return ec
for _, chain := range span.errorChains {
if chain.callstack.err == err {
return chain
}
}
return nil
Expand All @@ -87,6 +87,7 @@ func (span *span) traceCallStack(err error, depth int) int64 {
if !ok2 {
break
}

e = c.Cause()
if ec := span.findError(e); ec != nil {
eid = ec.exceptionId
Expand All @@ -105,12 +106,16 @@ func (span *span) traceCallStack(err error, depth int) int64 {
if eid == 0 {
eid = atomic.AddInt64(&exceptionIdGen, 1)
}
ecs := &errorWithCallStack{
err: err,
errorTime: time.Now(),
callstack: callstack,

chain := &errorChain{
callstack: &errorWithCallStack{
err: err,
errorTime: time.Now(),
callstack: callstack,
},
exceptionId: eid,
}
span.errorChains = append(span.errorChains, chain)

span.errorChains = append(span.errorChains, &errorChain{ecs: ecs, exceptionId: eid})
return eid
}

0 comments on commit 40324fe

Please sign in to comment.