@@ -35,18 +35,27 @@ class Pipeline {
35
35
protected Closure $ catcher ;
36
36
37
37
/**
38
- * @throws InvalidPipeError When invalid pipe given.
38
+ * @throws InvalidPipeError When invalid pipe given.
39
+ * @throws UnexpectedPipelineException When could not determine thrown exception.
39
40
* @phpstan-param class-string<Pipe>|Pipe|Closure(mixed $subject, Closure $next, mixed ...$use): mixed $pipe
40
41
*/
41
42
final public static function resolve ( string |Closure |Pipe $ pipe ): Closure {
42
43
$ isClassName = is_string ( $ pipe ) && class_exists ( $ pipe );
43
44
44
- return match ( true ) {
45
- default => throw InvalidPipeError::from ( $ pipe ),
46
- $ isClassName => PipelineBridge::make ( $ pipe )->handle ( ... ),
47
- $ pipe instanceof Pipe => $ pipe ->handle ( ... ),
48
- $ pipe instanceof Closure => $ pipe ,
49
- };
45
+ try {
46
+ return match ( true ) {
47
+ default => throw InvalidPipeError::from ( $ pipe ),
48
+ $ isClassName => PipelineBridge::make ( $ pipe )->handle ( ... ),
49
+ $ pipe instanceof Pipe => $ pipe ->handle ( ... ),
50
+ $ pipe instanceof Closure => $ pipe ,
51
+ };
52
+ } catch ( Throwable $ e ) {
53
+ if ( $ e instanceof InvalidPipeError ) {
54
+ throw $ e ;
55
+ }
56
+
57
+ throw new UnexpectedPipelineException ( $ e ->getMessage (), $ e ->getCode (), $ e );
58
+ }
50
59
}
51
60
52
61
/**
0 commit comments