From 88cf9b3a9d959597c12a3ef5404a09f84d773355 Mon Sep 17 00:00:00 2001 From: kazukousen Date: Tue, 9 Jan 2024 15:59:30 +0900 Subject: [PATCH] Add TopFrame function --- frame.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/frame.go b/frame.go index c9f41a9..4a8cd75 100644 --- a/frame.go +++ b/frame.go @@ -6,6 +6,27 @@ import ( "github.com/pkg/errors" ) +type ErrorSets []ErrorSet + +func (es ErrorSets) TopFrame() *Frame { + if len(es) == 0 { + return nil + } else if len(es[0].Frames) == 0 { + return nil + } + + top := es[0].Frames + + if p := es[0].Parent; p != nil { + top = top.Exclude(p) + } + if len(top) == 0 { + return nil + } + + return top[0] +} + type ErrorSet struct { Error error Frames Frames