Surface exceptions properly
This commit is contained in:
parent
eb14611b02
commit
01304a39fc
|
@ -20,6 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use danog\MadelineProto\Logger;
|
use danog\MadelineProto\Logger;
|
||||||
|
use danog\MadelineProto\RPCErrorException;
|
||||||
use League\Uri\Contracts\UriException;
|
use League\Uri\Contracts\UriException;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -158,6 +159,9 @@ class EventHandler extends \danog\MadelineProto\EventHandler
|
||||||
$this->report((string) $e);
|
$this->report((string) $e);
|
||||||
$this->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR);
|
$this->logger((string) $e, \danog\MadelineProto\Logger::FATAL_ERROR);
|
||||||
}
|
}
|
||||||
|
if ($e instanceof RPCErrorException && $e->rpc === 'FILE_PARTS_INVALID') {
|
||||||
|
$this->report(json_encode($url));
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
yield $this->messages->editMessage(['peer' => $peerId, 'id' => $id, 'message' => 'Error: '.$e->getMessage()]);
|
yield $this->messages->editMessage(['peer' => $peerId, 'id' => $id, 'message' => 'Error: '.$e->getMessage()]);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
|
|
|
@ -296,6 +296,7 @@ trait Files
|
||||||
};
|
};
|
||||||
|
|
||||||
$resPromises = [];
|
$resPromises = [];
|
||||||
|
$exception = null;
|
||||||
|
|
||||||
$start = \microtime(true);
|
$start = \microtime(true);
|
||||||
while ($part_num < $part_total_num) {
|
while ($part_num < $part_total_num) {
|
||||||
|
@ -308,17 +309,24 @@ trait Files
|
||||||
yield $writePromise;
|
yield $writePromise;
|
||||||
}
|
}
|
||||||
$writePromise->onResolve(
|
$writePromise->onResolve(
|
||||||
static function ($e, $readDeferred) use ($cb, $part_num, &$resPromises) {
|
function ($e, $readDeferred) use ($cb, $part_num, &$resPromises, &$exception) {
|
||||||
if ($e) {
|
if ($e) {
|
||||||
throw $e;
|
$this->logger("Got exception while uploading: $e");
|
||||||
|
$exception = $e;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
$resPromises []= $readDeferred->promise();
|
$resPromises []= $readDeferred->promise();
|
||||||
// Wrote chunk!
|
try {
|
||||||
if (!yield Tools::call($readDeferred->promise())) {
|
// Wrote chunk!
|
||||||
throw new \danog\MadelineProto\Exception('Upload of part '.$part_num.' failed');
|
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;
|
$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)
|
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);
|
yield Tools::all($promises);
|
||||||
$promises = [];
|
$promises = [];
|
||||||
|
if ($exception) {
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
|
|
||||||
$time = \microtime(true) - $start;
|
$time = \microtime(true) - $start;
|
||||||
$speed = (int) (($size * 8) / $time) / 1000000;
|
$speed = (int) (($size * 8) / $time) / 1000000;
|
||||||
|
|
|
@ -285,7 +285,7 @@ class PasswordCalculator
|
||||||
'p' => $pForHash,
|
'p' => $pForHash,
|
||||||
];
|
];
|
||||||
$new_settings['new_password_hash'] = $vForHash;
|
$new_settings['new_password_hash'] = $vForHash;
|
||||||
$new_settings['hint'] = $params['hint'];
|
$new_settings['hint'] = $params['hint'] ?? '';
|
||||||
if (isset($params['email'])) {
|
if (isset($params['email'])) {
|
||||||
$new_settings['email'] = $params['email'];
|
$new_settings['email'] = $params['email'];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue