@@ -21,77 +21,11 @@ namespace $ {
21
21
return this . errors . map ( e => e . message )
22
22
}
23
23
24
- static recursion_protect = new WeakMap < Error , true > ( )
25
-
26
- static find < Instance > (
27
- host : unknown ,
28
- is : ( e : unknown ) => boolean
29
- ) : Instance | null {
30
-
31
- if ( is ( host ) ) return host as Instance
32
- if ( ! ( host instanceof Error ) ) return null
33
- if ( this . recursion_protect . get ( host ) ) return null
34
-
35
- this . recursion_protect . set ( host , true )
36
-
37
- let sub
38
-
39
- if ( ! ( host instanceof $mol_error_mix ) && Array . isArray ( host . cause ) ) {
40
- for ( const e of host . cause ) {
41
- sub = this . find < Instance > ( e , is )
42
- if ( sub ) break
43
- }
44
- }
45
-
46
- if ( ! sub && host instanceof AggregateError ) {
47
- for ( const e of host . errors ) {
48
- sub = this . find < Instance > ( e , is )
49
- if ( sub ) break
50
- }
51
- }
52
-
53
- if ( ! sub ) sub = this . find < Instance > ( host . cause , is )
54
-
55
- this . recursion_protect . delete ( host )
56
-
57
- return sub
58
- }
59
-
60
- static filter < Instance > (
61
- host : unknown ,
62
- is : ( e : unknown ) => boolean
63
- ) : readonly Instance [ ] {
64
-
65
- const finded : Instance [ ] = [ ]
66
-
67
- this . find < Instance > ( host , e => {
68
- if ( is ( e ) ) finded . push ( e as Instance )
69
- return false
70
- } )
71
-
72
- return finded
73
- }
74
-
75
- filter < Instance > ( is : ( e : unknown ) => boolean ) {
76
- return $mol_error_mix . filter < Instance > ( this , is )
77
- }
78
-
79
- find < Instance > ( is : ( e : unknown ) => boolean ) {
80
- return $mol_error_mix . find < Instance > ( this , is )
81
- }
82
-
83
24
pick <
84
25
Instance extends Error ,
85
26
Class extends new ( ...args : any [ ] ) => Instance
86
27
> ( Class : Class ) {
87
- return this . find < Instance > ( e => e instanceof Class )
88
- }
89
-
90
- pick_all <
91
- Instance extends Error ,
92
- Class extends new ( ...args : any [ ] ) => Instance
93
- > ( Class : Class ) {
94
- return this . filter < Instance > ( e => e instanceof Class )
28
+ return $mol_error_match < Instance > ( this , e => e instanceof Class )
95
29
}
96
30
97
31
}
0 commit comments