Skip to content

Commit

Permalink
Add TopFrame function
Browse files Browse the repository at this point in the history
  • Loading branch information
kazukousen committed Jan 9, 2024
1 parent 4a500fe commit aca88df
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pperr.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,23 @@ func CauseType(err error) string {
err = cause
}
}

func TopFrame(es []ErrorSet) (*Frame, error) {
if len(es) == 0 {
return nil, fmt.Errorf("length of es greater than 0")
} else if len(es[0].Frames) == 0 {
return nil, fmt.Errorf("length of es[0].Frames greater than 0")
}

top := es[0].Frames

if p := es[0].Parent; p != nil {
top = top.Exclude(p)
}

if len(top) == 0 {
return nil, fmt.Errorf("unique top frame not found")
}

return top[0], nil
}

0 comments on commit aca88df

Please sign in to comment.