From 9264a2e99ba85ecbc0de342d786965283137dc57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Fri, 5 Jan 2024 10:43:39 +0100 Subject: [PATCH] v0.0.356 exerr.GetMeta --- exerr/exerr.go | 12 ++++++++++++ goextVersion.go | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/exerr/exerr.go b/exerr/exerr.go index 02887c5..01855d2 100644 --- a/exerr/exerr.go +++ b/exerr/exerr.go @@ -258,6 +258,18 @@ func (ee *ExErr) Depth() int { } } +// GetMeta returns the meta value with the specified key +// this method recurses through all wrapped errors and returns the first matching meta value +func (ee *ExErr) GetMeta(key string) (any, bool) { + for curr := ee; curr != nil; curr = curr.OriginalError { + if v, ok := curr.Meta[key]; ok { + return v.Value, true + } + } + + return nil, false +} + // contains test if the supplied error is contained in this error (anywhere in the chain) func (ee *ExErr) contains(original *ExErr) (*ExErr, bool) { if original == nil { diff --git a/goextVersion.go b/goextVersion.go index 2d1eaec..c0a20c4 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.355" +const GoextVersion = "0.0.356" -const GoextVersionTimestamp = "2024-01-05T10:25:05+0100" +const GoextVersionTimestamp = "2024-01-05T10:43:39+0100"