Skip to content

Commit 9f1f883

Browse files
committed
implement Type.HasTrait(trait)
1 parent b2e3478 commit 9f1f883

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

error.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ func (e *Error) HasTrait(key Trait) bool {
8989
cause := e
9090
for cause != nil {
9191
if !cause.transparent {
92-
_, ok := cause.errorType.traits[key]
93-
return ok
92+
return cause.errorType.HasTrait(key)
9493
}
9594

9695
cause = Cast(cause.Cause())

type.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ func (t *Type) IsOfType(other *Type) bool {
8888
return false
8989
}
9090

91+
// HasTrait checks if a type possesses the expected trait.
92+
func (t *Type) HasTrait(key Trait) bool {
93+
_, ok := t.traits[key]
94+
return ok
95+
}
96+
9197
// IsOfType is a type check for errors.
9298
// Returns true either if both are of exactly the same type, or if the same is true for one of current type's ancestors.
9399
// For an error that does not have an errorx type, returns false.

0 commit comments

Comments
 (0)