Send the logfile when reporting errors

This commit is contained in:
Daniil Gentili 2020-02-26 12:45:30 +01:00
parent 753e6575ac
commit e50dd79e70
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
9 changed files with 57 additions and 21 deletions

View File

@ -86,7 +86,7 @@ You can find examples for nearly every MadelineProto function in
* [Handling updates (new messages)](https://docs.madelineproto.xyz/docs/UPDATES.html)
* [Self-restart on webhosts](https://docs.madelineproto.xyz/docs/UPDATES.html#self-restart-on-webhosts)
* [Async Event driven](https://docs.madelineproto.xyz/docs/UPDATES.html#async-event-driven)
* [Multi-account: Async Combined Event driven update handling](https://docs.madelineproto.xyz/docs/UPDATES.html#async-combined-event-driven)
* [Multi-account: Async Event driven](https://docs.madelineproto.xyz/docs/UPDATES.html#async-event-driven)
* [Async Callback](https://docs.madelineproto.xyz/docs/UPDATES.html#async-callback)
* [Noop (default)](https://docs.madelineproto.xyz/docs/UPDATES.html#noop)
* [Fetch all updates from the beginning](https://docs.madelineproto.xyz/docs/UPDATES.html#fetch-all-updates-from-the-beginning)

View File

@ -19,7 +19,6 @@
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
use Amp\Loop;
use danog\MadelineProto\API;
use danog\MadelineProto\EventHandler;
use danog\MadelineProto\Exception;

View File

@ -128,7 +128,7 @@ class API extends InternalDoc
public function __construct_async(string $session, array $settings = []): \Generator
{
Logger::constructorFromSettings($settings);
$session = Absolute::absolute($session);
$this->session = $session = Absolute::absolute($session);
if ($unserialized = yield from Serialization::legacyUnserialize($session)) {
$unserialized->storage = $unserialized->storage ?? [];
$unserialized->session = $session;
@ -235,10 +235,7 @@ class API extends InternalDoc
} catch (\Throwable $e) {
$thrown = true;
$this->logger((string) $e, Logger::FATAL_ERROR);
try {
$this->report("Surfaced: $e");
} catch (\Throwable $e) {
}
}
} while ($thrown);
}

View File

@ -5540,11 +5540,11 @@ class InternalDoc extends APIFactory
*
* @param string|EventHandler $event_handler Event handler
*
* @return void
* @return \Generator
*/
public function setEventHandler($event_handler): void
public function setEventHandler($event_handler, array $extra = [])
{
$this->API->setEventHandler($event_handler);
return $this->__call(__FUNCTION__, [$event_handler, $extra]);
}
/**
* Unset event handler.

View File

@ -70,6 +70,12 @@ class Logger
* @var string
*/
public $newline = "\n";
/**
* Logfile
*
* @var ResourceOutputStream
*/
public $stdout;
/**
* Default logger instance.
*

File diff suppressed because one or more lines are too long

View File

@ -49,9 +49,9 @@ trait Events
*
* @param string|EventHandler $event_handler Event handler
*
* @return void
* @return \Generator
*/
public function setEventHandler($event_handler): void
public function setEventHandler($event_handler): \Generator
{
if (!\class_exists($event_handler) || !\is_subclass_of($event_handler, '\\danog\\MadelineProto\\EventHandler')) {
throw new \danog\MadelineProto\Exception('Wrong event handler was defined');
@ -80,7 +80,7 @@ trait Events
}
}
}
$this->setReportPeers($this->event_handler_instance->getReportPeers());
yield from $this->setReportPeers($this->event_handler_instance->getReportPeers());
$this->settings['updates']['callback'] = [$this, 'eventUpdateHandler'];
$this->settings['updates']['handle_updates'] = true;
$this->settings['updates']['run_callback'] = true;

View File

@ -25,6 +25,7 @@ class FileIdTest extends TestCase
public static function setUpBeforeClass(): void
{
self::$MadelineProto = new API(
'testing.madeline',
[
'app_info' => [
'api_id' => \getenv('API_ID'),