-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Introduce dedicated
CatchUpHadErrors
exception
- Loading branch information
Showing
5 changed files
with
83 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
Neos.ContentRepository.Core/Classes/Subscription/Exception/CatchUpHadErrors.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\ContentRepository\Core\Subscription\Exception; | ||
|
||
use Neos\ContentRepository\Core\Projection\CatchUpHook\CatchUpHookFailed; | ||
use Neos\ContentRepository\Core\Subscription\Engine\Error; | ||
use Neos\ContentRepository\Core\Subscription\Engine\Errors; | ||
|
||
/** | ||
* Thrown if the subscribers could not be catchup without encountering errors. | ||
* | ||
* Still, as we collect the errors and don't halt the process the system will be still up-to-date as far as possible. | ||
* | ||
* Following reasons would trigger this error: | ||
* | ||
* - A projection has a failure in its code. Then the projection is rolled back to the last event and put into ERROR state. | ||
* An exception will be part of this collection indicating this change. Further catchup's will not attempt to update that | ||
* projection again, as it has to be fixed and reactivated first. | ||
* | ||
* - A catchup hook contains an error. In this case the projections is further updated and also all further catchup errors | ||
* collected. This results in a {@see CatchUpHookFailed} exception in this exception collection. | ||
* | ||
* @implements \IteratorAggregate<\Throwable> | ||
* @api | ||
*/ | ||
final class CatchUpHadErrors extends \RuntimeException implements \IteratorAggregate | ||
{ | ||
/** | ||
* @internal | ||
* @param array<\Throwable> $additionalExceptions | ||
*/ | ||
private function __construct( | ||
string $message, | ||
int $code, | ||
\Throwable $exception, | ||
private readonly array $additionalExceptions | ||
) { | ||
parent::__construct($message, $code, $exception); | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public static function createFromErrors(Errors $errors): self | ||
{ | ||
/** @var non-empty-array<Error> $errors */ | ||
$errors = iterator_to_array($errors); | ||
$firstError = array_shift($errors); | ||
|
||
$additionalFailedSubscribers = array_map(fn (Error $error) => $error->subscriptionId->value, $errors); | ||
|
||
$additionalErrors = $additionalFailedSubscribers === [] ? '' : sprintf(' | And subscribers %s with additional errors.', join(', ', $additionalFailedSubscribers)); | ||
$exceptionMessage = sprintf('Exception in subscriber "%s" while catching up: %s%s', $firstError->subscriptionId->value, $firstError->message, $additionalErrors); | ||
|
||
throw new self($exceptionMessage, 1732132930, $firstError->throwable, array_map(fn (Error $error) => $error->throwable, $errors)); | ||
} | ||
|
||
public function getIterator(): \Traversable | ||
{ | ||
$previous = $this->getPrevious(); | ||
if ($previous !== null) { | ||
yield $previous; | ||
} | ||
yield from $this->additionalExceptions; | ||
} | ||
} |