php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.87k stars 951 forks source link

ErrorException in TelegramLog.php #413

Closed chuv1 closed 7 years ago

chuv1 commented 7 years ago

I finished with my own crash notifier, based on this comment and curl request to api endpoint in case of errors. It notifies me by bot itself about Exceptions in code.

So it started to notify my about

ErrorException - vsprintf(): Too few arguments;
File: /bla-bla-bla/vendor/longman/telegram-bot/src/TelegramLog.php; Line: 292;

when message text contains percent sign. Incoming message example (cleaned for privacy):

array (
  'update_id' => 408xxxxxx,
  'message' => 
  array (
    'message_id' => 4xxxx,
    'from' => 
    array (
      'id' => 8xxxx,
      'first_name' => 'Kxxxx',
      'last_name' => 'Nxxxxxxxx',
      'username' => 'xxxxxx',
    ),
    'chat' => 
    array (
      'id' => -1001xxxxxxxxxx,
      'title' => 'xxxxxxx',
      'username' => 'xxxxxxxx',
      'type' => 'supergroup',
    ),
    'date' => xxxxxxxxxx,
    'text' => 'Помню только 100% качество, уникальную скидку, кучу подарков, и это ещё не всё, позвоните прямо сейчас и…',
  ),
)

and another one

array (
  'update_id' => 408xxxxxx,
  'message' => 
  array (
    'message_id' => 3xxxxxx,
    'from' => 
    array (
      'id' => 1xxxxxxxx,
      'first_name' => 'Mxxxxxxx',
      'username' => 'xxxxxxxx',
    ),
    'chat' => 
    array (
      'id' => -1001xxxxxxxxx,
      'title' => 'xxxxxxxxx',
      'username' => 'xxxxxxxxx',
      'type' => 'supergroup',
    ),
    'date' => xxxxxxxxxx,
    'text' => 'В результате естественного отбора отфильтровалось  3-5 удобоваримых и удовлетворяющих мои нужды на 99,9(9)%  интерфейса , зачем мне их 44 , 144? Зачем мне из менять и перебирать? Я конечно понимаю, что среди овер7млрд. человек найдутся люди или даже группа людей кому этот процесс доставляет удовольствие или может у них хобби такое... я не из них ) Про авиасейлс не совсем понял... ',
  ),
)

PS. I'm using 0.39 version.

noplanman commented 7 years ago

Correct thing in this situation is to replace % with %% to escape the percent sign 👍

chuv1 commented 7 years ago

So this is my fault, no? I just turned logging on in hook...

noplanman commented 7 years ago

D'oh, didn't read the error properly, thought that you were using vsprintf, just noticed it's the logger...

No, it's not your fault, it's mine. Didn't test for that case...

Will fix it for the next release 👍 Thanks for letting us know!

noplanman commented 7 years ago

As I'm fixing this, I wonder why you got this error message, as it should get suppressed by the @ here.

You do have it there, right?

chuv1 commented 7 years ago

Yes, I have it. Could be because of this?

ini_set( "display_errors", "off" );
error_reporting( E_ALL );

from this comment

noplanman commented 7 years ago

I don't think so.

Have tried to add that myself and it still gets suppressed, weird.

Fix incoming... 😇

chuv1 commented 7 years ago

No, found out that it's my fault -

If you have set a custom error handler function with set_error_handler() then it will still get called, but this custom error handler can (and should) call error_reporting() which will return 0 when the call that triggered the error was preceded by an @. from php.net

noplanman commented 7 years ago

Ok, PR is open here #414

Could you try to add the code to your bot and see if it's fixed now?

If yes, I'll merge and then release 0.40.0

chuv1 commented 7 years ago

Yes, works fine with that fix. Custom handler not triggered anymore.

noplanman commented 7 years ago

No, found out that it's my fault

Not at all! You may have triggered the bug, but it was my bad 😉

Keep breaking stuff!! 👍

chuv1 commented 7 years ago

Ok, I will. ))))) Thanks for your work guys!