EnsureNotInDomain checks whether the error is in the given domain(s). If it is, the given constructor if provided is called to construct an alternate error. If no error constructor is provided, a new barrier is constructed automatically using the first provided domain as new domain. The original err
( err error, constructor func(originalDomain Domain, err error) error, forbiddenDomains ...Domain, )
| 122 | // provided domain as new domain. The original error message |
| 123 | // is preserved. |
| 124 | func EnsureNotInDomain( |
| 125 | err error, constructor func(originalDomain Domain, err error) error, forbiddenDomains ...Domain, |
| 126 | ) error { |
| 127 | if err == nil { |
| 128 | return nil |
| 129 | } |
| 130 | |
| 131 | // Is the error already in the wanted domains? |
| 132 | errDomain := GetDomain(err) |
| 133 | if notInDomainInternal(errDomain, forbiddenDomains...) { |
| 134 | // No: no-op. |
| 135 | return err |
| 136 | } |
| 137 | return constructor(errDomain, err) |
| 138 | } |
| 139 | |
| 140 | // PackageDomain returns an error domain that represents the |
| 141 | // package of its caller. |
no test coverage detected
searching dependent graphs…