Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3e34ef0

Browse files
committed
[Messenger] add handler description as array key toHandlerFailedException::getWrappedExceptions()
1 parente11ae31 commit3e34ef0

File tree

7 files changed

+45
-11
lines changed

7 files changed

+45
-11
lines changed

‎src/Symfony/Component/Messenger/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CHANGELOG
1212
* Add`WrappedExceptionsInterface` interface for exceptions that hold multiple individual exceptions
1313
* Deprecate`HandlerFailedException::getNestedExceptions()`,`HandlerFailedException::getNestedExceptionsOfClass()`
1414
and`DelayedMessageHandlingException::getExceptions()` which are replaced by a new`getWrappedExceptions()` method
15+
* Add handler description as array key to`HandlerFailedException::getWrappedExceptions()`
1516

1617
6.3
1718
---

‎src/Symfony/Component/Messenger/Exception/HandlerFailedException.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class HandlerFailedException extends RuntimeException implements WrappedExceptio
2121
privateEnvelope$envelope;
2222

2323
/**
24-
* @param \Throwable[] $exceptions
24+
* @paramarray<string,\Throwable> $exceptions The name of the handler should be given as key
2525
*/
2626
publicfunction__construct(Envelope$envelope,array$exceptions)
2727
{
@@ -50,7 +50,7 @@ public function getEnvelope(): Envelope
5050
/**
5151
* @deprecated since Symfony 6.4, use {@see self::getWrappedExceptions()} instead
5252
*
53-
* @return \Throwable[]
53+
* @returnarray<string,\Throwable> The name of the handler should be given as key
5454
*/
5555
publicfunctiongetNestedExceptions():array
5656
{

‎src/Symfony/Component/Messenger/Exception/WrappedExceptionsInterface.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
interface WrappedExceptionsInterface
2020
{
2121
/**
22-
* @return \Throwable[]
22+
* @returnarray<string,\Throwable>
2323
*/
2424
publicfunctiongetWrappedExceptions(string$class =null,bool$recursive =false):array;
2525
}

‎src/Symfony/Component/Messenger/Exception/WrappedExceptionsTrait.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
trait WrappedExceptionsTrait
2020
{
2121
/**
22-
* @return \Throwable[]
22+
* @returnarray<array-key,\Throwable>
2323
*/
2424
publicfunctiongetWrappedExceptions(string$class =null,bool$recursive =false):array
2525
{
@@ -30,7 +30,7 @@ public function getWrappedExceptions(string $class = null, bool $recursive = fal
3030
* @param class-string<\Throwable>|null $class
3131
* @param iterable<\Throwable> $exceptions
3232
*
33-
* @return \Throwable[]
33+
* @returnarray<array-key,\Throwable>
3434
*/
3535
privatefunctiongetWrappedExceptionsRecursively(?string$class,bool$recursive,iterable$exceptions):array
3636
{

‎src/Symfony/Component/Messenger/Middleware/HandleMessageMiddleware.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope
6666
if ($batchHandler &&$ackStamp =$envelope->last(AckStamp::class)) {
6767
$ack =newAcknowledger(get_debug_type($batchHandler),staticfunction (\Throwable$e =null,$result =null)use ($envelope,$ackStamp,$handlerDescriptor) {
6868
if (null !==$e) {
69-
$e =newHandlerFailedException($envelope, [$e]);
69+
$e =newHandlerFailedException($envelope, [$handlerDescriptor->getName() =>$e]);
7070
}else {
7171
$envelope =$envelope->with(HandledStamp::fromDescriptor($handlerDescriptor,$result));
7272
}
@@ -95,7 +95,7 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope
9595
$envelope =$envelope->with($handledStamp);
9696
$this->logger?->info('Message {class} handled by {handler}',$context + ['handler' =>$handledStamp->getHandlerName()]);
9797
}catch (\Throwable$e) {
98-
$exceptions[] =$e;
98+
$exceptions[$handlerDescriptor->getName()] =$e;
9999
}
100100
}
101101

@@ -107,7 +107,7 @@ public function handle(Envelope $envelope, StackInterface $stack): Envelope
107107
$handler =$stamp->getHandlerDescriptor()->getBatchHandler();
108108
$handler->flush($flushStamp->force());
109109
}catch (\Throwable$e) {
110-
$exceptions[] =$e;
110+
$exceptions[$stamp->getHandlerDescriptor()->getName()] =$e;
111111
}
112112
}
113113
}

‎src/Symfony/Component/Messenger/Tests/Exception/HandlerFailedExceptionTest.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function testThatWrappedExceptionsRecursive()
7575
$exception2 =newMyOwnException('second');
7676
$exception3 =newMyOwnException('third');
7777

78-
$handlerException =newHandlerFailedException($envelope, [$exception1,$exception2,newDelayedMessageHandlingException([$exception3])]);
78+
$handlerException =newHandlerFailedException($envelope, [$exception1,$exception2,newDelayedMessageHandlingException([$exception3],$envelope)]);
7979
$this->assertSame([$exception1,$exception2,$exception3],$handlerException->getWrappedExceptions(recursive:true));
8080
}
8181

@@ -86,7 +86,7 @@ public function testThatWrappedExceptionsRecursiveStringKeys()
8686
$exception2 =newMyOwnException('second');
8787
$exception3 =newMyOwnException('third');
8888

89-
$handlerException =newHandlerFailedException($envelope, ['first' =>$exception1,'second' =>$exception2,newDelayedMessageHandlingException(['third' =>$exception3])]);
89+
$handlerException =newHandlerFailedException($envelope, ['first' =>$exception1,'second' =>$exception2,newDelayedMessageHandlingException(['third' =>$exception3],$envelope)]);
9090
$this->assertSame(['first' =>$exception1,'second' =>$exception2,'third' =>$exception3],$handlerException->getWrappedExceptions(recursive:true));
9191
}
9292

@@ -97,7 +97,7 @@ public function testThatWrappedExceptionsByClassRecursive()
9797
$exception2 =newMyOwnException('second');
9898
$exception3 =newMyOwnException('third');
9999

100-
$handlerException =newHandlerFailedException($envelope, [$exception1,$exception2,newDelayedMessageHandlingException([$exception3])]);
100+
$handlerException =newHandlerFailedException($envelope, [$exception1,$exception2,newDelayedMessageHandlingException([$exception3],$envelope)]);
101101
$this->assertSame([$exception2,$exception3],$handlerException->getWrappedExceptions(class: MyOwnException::class, recursive:true));
102102
}
103103
}

‎src/Symfony/Component/Messenger/Tests/Middleware/HandleMessageMiddlewareTest.php‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,31 @@ public function testItCallsTheHandlerAndNextMiddleware()
4747
$middleware->handle($envelope,$this->getStackMock());
4848
}
4949

50+
publicfunctiontestItKeysTheHandlerFailedNestedExceptionsByHandlerDescription()
51+
{
52+
$message =newDummyMessage('Hey');
53+
$envelope =newEnvelope($message);
54+
$handler =newFailingHandleMessageMiddlewareTestCallable();
55+
56+
$middleware =newHandleMessageMiddleware(newHandlersLocator([
57+
DummyMessage::class => [$handler],
58+
]));
59+
60+
try {
61+
$middleware->handle($envelope,$this->getStackMock(false));
62+
}catch (HandlerFailedException$e) {
63+
$key = (newHandlerDescriptor($handler))->getName();
64+
65+
$this->assertCount(1,$e->getWrappedExceptions());
66+
$this->assertArrayHasKey($key,$e->getWrappedExceptions());
67+
$this->assertSame('failed',$e->getWrappedExceptions()[$key]->getMessage());
68+
69+
return;
70+
}
71+
72+
$this->fail('Exception not thrown.');
73+
}
74+
5075
/**
5176
* @dataProvider itAddsHandledStampsProvider
5277
*/
@@ -335,6 +360,14 @@ public function __invoke()
335360
}
336361
}
337362

363+
class FailingHandleMessageMiddlewareTestCallable
364+
{
365+
publicfunction__invoke()
366+
{
367+
thrownew \Exception('failed');
368+
}
369+
}
370+
338371
class HandleMessageMiddlewareNamedArgumentTestCallable
339372
{
340373
publicfunction__invoke(object$message,$namedArgument)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp