1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-22 19:51:11 +01:00

Intercept and rethrow exceptions during update handling

This commit is contained in:
Daniil Gentili 2023-02-06 15:14:02 +01:00
parent f139decef3
commit bfea44e0df
3 changed files with 14 additions and 2 deletions

View File

@ -50,6 +50,13 @@ use function Amp\Future\awaitFirst;
*/
abstract class AsyncTools extends StrTools
{
/**
* Rethrow exception into event loop.
*/
public static function rethrow(\Throwable $e): void
{
EventLoop::queue(fn () => throw $e);
}
/**
* Synchronously wait for a Future|generator.
*

View File

@ -21,6 +21,7 @@ declare(strict_types=1);
namespace danog\MadelineProto\Loop\Update;
use danog\Loop\Loop;
use danog\MadelineProto\AsyncTools;
use danog\MadelineProto\Logger;
use danog\MadelineProto\Loop\InternalLoop;
use danog\MadelineProto\MTProto;
@ -85,7 +86,11 @@ final class FeedLoop extends Loop
$parsedUpdates = $this->parsedUpdates;
$this->parsedUpdates = [];
foreach ($parsedUpdates as $update) {
$this->API->saveUpdate($update);
try {
$this->API->saveUpdate($update);
} catch (\Throwable $e) {
AsyncTools::rethrow($e);
}
}
$parsedUpdates = null;
}

View File

@ -500,7 +500,7 @@ trait UpdateHandler
throw $e;
}
} catch (RPCErrorException $e) {
if ($e->rpc !== 'CHANNEL_PRIVATE') {
if ($e->rpc !== 'CHANNEL_PRIVATE' && $e->rpc !== 'MSG_ID_INVALID') {
throw $e;
}
}