diff --git a/examples/downloadRenameBot.php b/examples/downloadRenameBot.php index c0c2603f..e7ff555a 100755 --- a/examples/downloadRenameBot.php +++ b/examples/downloadRenameBot.php @@ -20,6 +20,7 @@ */ use danog\MadelineProto\Logger; +use danog\MadelineProto\RPCErrorException; use League\Uri\Contracts\UriException; /* @@ -158,6 +159,9 @@ class EventHandler extends \danog\MadelineProto\EventHandler $this->report((string) $e); $this->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR); } + if ($e instanceof RPCErrorException && $e->rpc === 'FILE_PARTS_INVALID') { + $this->report(json_encode($url)); + } try { yield $this->messages->editMessage(['peer' => $peerId, 'id' => $id, 'message' => 'Error: '.$e->getMessage()]); } catch (\Throwable $e) { diff --git a/src/danog/MadelineProto/MTProtoTools/Files.php b/src/danog/MadelineProto/MTProtoTools/Files.php index 84e3e8d8..3a813e18 100644 --- a/src/danog/MadelineProto/MTProtoTools/Files.php +++ b/src/danog/MadelineProto/MTProtoTools/Files.php @@ -296,6 +296,7 @@ trait Files }; $resPromises = []; + $exception = null; $start = \microtime(true); while ($part_num < $part_total_num) { @@ -308,17 +309,24 @@ trait Files yield $writePromise; } $writePromise->onResolve( - static function ($e, $readDeferred) use ($cb, $part_num, &$resPromises) { + function ($e, $readDeferred) use ($cb, $part_num, &$resPromises, &$exception) { if ($e) { - throw $e; + $this->logger("Got exception while uploading: $e"); + $exception = $e; + return; } $resPromises []= $readDeferred->promise(); - // Wrote chunk! - if (!yield Tools::call($readDeferred->promise())) { - throw new \danog\MadelineProto\Exception('Upload of part '.$part_num.' failed'); + try { + // Wrote chunk! + if (!yield Tools::call($readDeferred->promise())) { + throw new \danog\MadelineProto\Exception('Upload of part '.$part_num.' failed'); + } + // Got OK from server for chunk! + $cb(); + } catch (\Throwable $e) { + $this->logger("Got exception while uploading: $e"); + $exception = $e; } - // Got OK from server for chunk! - $cb(); } ); $promises []= $writePromise; @@ -327,6 +335,9 @@ trait Files if (!($part_num % $parallel_chunks)) { // By default, 10 mb at a time, for a typical bandwidth of 1gbps (run the code in this every second) yield Tools::all($promises); $promises = []; + if ($exception) { + throw $exception; + } $time = \microtime(true) - $start; $speed = (int) (($size * 8) / $time) / 1000000; diff --git a/src/danog/MadelineProto/MTProtoTools/PasswordCalculator.php b/src/danog/MadelineProto/MTProtoTools/PasswordCalculator.php index 5b24b6ed..4a01e5b6 100644 --- a/src/danog/MadelineProto/MTProtoTools/PasswordCalculator.php +++ b/src/danog/MadelineProto/MTProtoTools/PasswordCalculator.php @@ -285,7 +285,7 @@ class PasswordCalculator 'p' => $pForHash, ]; $new_settings['new_password_hash'] = $vForHash; - $new_settings['hint'] = $params['hint']; + $new_settings['hint'] = $params['hint'] ?? ''; if (isset($params['email'])) { $new_settings['email'] = $params['email']; }