danog / MadelineProto

Async PHP client API for the telegram MTProto protocol
https://docs.madelineproto.xyz
GNU Affero General Public License v3.0
2.83k stars 654 forks source link

Ability to disable logger or custom exception handler #1420

Closed BoShurik closed 1 year ago

BoShurik commented 1 year ago

For example, we have a "symfony/validator": "^6.4@dev" dependency with this code:

require __DIR__ . '/../vendor/autoload.php';

$builder = new ValidatorBuilder();
$builder->enableAnnotationMapping();

$validator = $builder->getValidator();

It works fine. enableAnnotationMapping in this version is deprecated, but silenced and can be catch by logger.

If we add MadelineProto to this script:

require __DIR__ . '/../vendor/autoload.php';

// $settings = ...
$madelineProto = new API('session.madeline.exception', $settings);

$builder = new ValidatorBuilder();
$builder->enableAnnotationMapping();

$validator = $builder->getValidator();

We got an exception

\danog\MadelineProto\Exception: Since symfony/validator 6.4: Method "Symfony\Component\Validator\ValidatorBuilder::enableAnnotationMapping()" is deprecated, use "enableAttributeMapping()" instead. in vendor/symfony/deprecation-contracts/function.php:25

It would be great to have an ability to disable this behaviour

mtalaeii commented 1 year ago

You must handle excaption and correct your code disabling logger and keep using deprecated function not a good idea by the way the code suggest you using enableAttributeMapping() function instead

danog commented 1 year ago

What @mtalaeii said, however if you really have issues with the strict error handler you can always overwrite it after instantiating API.

BoShurik commented 1 year ago

You must handle excaption

It's not an exception, it's deprecation warning. MadelineProto converts this warning to the exception.

disabling logger and keep using deprecated function not a good idea by the way the code suggest you using enableAttributeMapping() function instead

It was just an example. And often there are no suggestion like in this example.

Symfony often use this method to trigger deprecation warning and collect them in separate log file. MadelineProto brakes this behavior by adding own handlers and converting warning to exceptions.

danog commented 1 year ago

Deprecation warnings are there to be solved, not to be ignored :)

BoShurik commented 1 year ago

Deprecation warnings are there to be solved, not to be ignored :)

Yes, but I would prefer application did not crash in runtime because of that ;)

BoShurik commented 1 year ago

At least, it would be good to ignore silenced exception. E.g. symfony uses it in symfony/var-dumper. So messages with \danog\MadelineProto\TL\Types\Bytes cant be dumped because of strict error handler

danog commented 1 year ago

You can re-set the error handler after instantiating madelineproto (even if it's generally not recommended)

BoShurik commented 1 year ago

Yes, I can. But it reduces DX.

Anyway, thanks for the quick reply and the great project!

BoShurik commented 1 year ago

My workaround