Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Fixed

- `Any::from()` was erasing guarded errors

## 5.1.0 - 2025-09-06

### Added
Expand Down
55 changes: 55 additions & 0 deletions proofs/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Any,
Respond,
Collect,
Pipe,
};
use Innmind\Http;
use Innmind\Url\Url;
Expand Down Expand Up @@ -322,6 +323,60 @@ static function($assert, $url, $method, $wrongMethod, $protocolVersion, $status)
},
);

yield proof(
'Any::from() should not override user errors',
given(
Set::of(...Http\Method::cases()),
Set::of(...Http\Method::cases()),
Set::of(...Http\ProtocolVersion::cases()),
),
static function($assert, $method, $other, $protocolVersion) {
$in = Http\ServerRequest::of(
Url::of('/foo'),
$method,
$protocolVersion,
);
$expected = new Exception;
$router = Router::of(
Any::from(Sequence::of(
Pipe::new()
->{$method->name}()
->handle(static fn() => Attempt::error($expected)),
Pipe::new()
->{$other->name}()
->handle(static fn() => Attempt::error(new Exception)),
)),
);

$assert->same(
$expected,
$router($in)->match(
static fn($response) => $response,
static fn($error) => $error,
),
);

$router = Router::of(
Any::from(Sequence::of(
Pipe::new()
->{$method->name}()
->handle(static fn() => Attempt::error($expected)),
Pipe::new()
->{$other->name}()
->handle(static fn() => Attempt::error(new Exception)),
)),
);

$assert->same(
$expected,
$router($in)->match(
static fn($response) => $response,
static fn($error) => $error,
),
);
},
);

yield proof(
'Respond::with()',
given(
Expand Down
4 changes: 2 additions & 2 deletions src/Any.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ static function($previous, $component, $continuation) use ($beacon, $request, $i

// If the new error is the beacon then it means the
// previous error was a guarded one and it will try to
// recover from it. So we can stop iterating other
// recover from it. So we can stop iterating over other
// components.
return $result->match(
static fn() => $continuation->stop($result),
static fn($e) => match ($e) {
$beacon => $continuation->stop($result),
$beacon => $continuation->stop($previous),
default => $continuation->continue($result),
},
);
Expand Down
2 changes: 1 addition & 1 deletion src/Pipe/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle(callable $handle): Component
{
return $this
->toComponent()
->pipe(Handle::via($handle));
->feed(Handle::via($handle));
}

#[\NoDiscard]
Expand Down
2 changes: 1 addition & 1 deletion src/Pipe/Forward/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function handle(callable $handle): Component
{
return $this
->toComponent()
->pipe(Handle::via($handle));
->feed(Handle::via($handle));
}

public function spread(): Method\Spread
Expand Down
2 changes: 1 addition & 1 deletion src/Pipe/Method/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function handle(callable $handle): Component
{
return $this
->toComponent()
->pipe(Handle::via($handle));
->feed(Handle::via($handle));
}

#[\NoDiscard]
Expand Down