|
|
|
@@ -258,6 +258,73 @@ 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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetMetaString functions the same as GetMeta, but returns false if the type does not match
|
|
|
|
|
func (ee *ExErr) GetMetaString(key string) (string, bool) {
|
|
|
|
|
if v1, ok := ee.GetMeta(key); ok {
|
|
|
|
|
if v2, ok := v1.(string); ok {
|
|
|
|
|
return v2, true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "", false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ee *ExErr) GetMetaBool(key string) (bool, bool) {
|
|
|
|
|
if v1, ok := ee.GetMeta(key); ok {
|
|
|
|
|
if v2, ok := v1.(bool); ok {
|
|
|
|
|
return v2, true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false, false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ee *ExErr) GetMetaInt(key string) (int, bool) {
|
|
|
|
|
if v1, ok := ee.GetMeta(key); ok {
|
|
|
|
|
if v2, ok := v1.(int); ok {
|
|
|
|
|
return v2, true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0, false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ee *ExErr) GetMetaFloat32(key string) (float32, bool) {
|
|
|
|
|
if v1, ok := ee.GetMeta(key); ok {
|
|
|
|
|
if v2, ok := v1.(float32); ok {
|
|
|
|
|
return v2, true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0, false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ee *ExErr) GetMetaFloat64(key string) (float64, bool) {
|
|
|
|
|
if v1, ok := ee.GetMeta(key); ok {
|
|
|
|
|
if v2, ok := v1.(float64); ok {
|
|
|
|
|
return v2, true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0, false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ee *ExErr) GetMetaTime(key string) (time.Time, bool) {
|
|
|
|
|
if v1, ok := ee.GetMeta(key); ok {
|
|
|
|
|
if v2, ok := v1.(time.Time); ok {
|
|
|
|
|
return v2, true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return time.Time{}, 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 {
|
|
|
|
|