File: error_113.go

package info (click to toggle)
golang-github-joomcode-errorx 1.2.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 280 kB
  • sloc: makefile: 2
file content (38 lines) | stat: -rw-r--r-- 608 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// +build go1.13

package errorx

import "errors"

func isOfType(err error, t *Type) bool {
	e := burrowForTyped(err)
	return e != nil && e.IsOfType(t)
}

func (e *Error) isOfType(t *Type) bool {
	cause := e
	for cause != nil {
		if !cause.transparent {
			return cause.errorType.IsOfType(t)
		}

		cause = burrowForTyped(cause.Cause())
	}

	return false
}

// burrowForTyped returns either the first *Error in unwrap chain or nil
func burrowForTyped(err error) *Error {
	raw := err
	for raw != nil {
		typed := Cast(raw)
		if typed != nil {
			return typed
		}

		raw = errors.Unwrap(raw)
	}

	return nil
}