Skip to content

Commit e34ec41

Browse files
committed
Throws UnexpectedPipelineException if unknown exception caught.
1 parent cf376c6 commit e34ec41

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Src/Pipeline.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,27 @@ class Pipeline {
3535
protected Closure $catcher;
3636

3737
/**
38-
* @throws InvalidPipeError When invalid pipe given.
38+
* @throws InvalidPipeError When invalid pipe given.
39+
* @throws UnexpectedPipelineException When could not determine thrown exception.
3940
* @phpstan-param class-string<Pipe>|Pipe|Closure(mixed $subject, Closure $next, mixed ...$use): mixed $pipe
4041
*/
4142
final public static function resolve( string|Closure|Pipe $pipe ): Closure {
4243
$isClassName = is_string( $pipe ) && class_exists( $pipe );
4344

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+
}
5059
}
5160

5261
/**

0 commit comments

Comments
 (0)