rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.68k stars 1.18k forks source link

BaseAbilityBot.runSilently does not provide information on what exactly went wrong #886

Open allavett opened 3 years ago

allavett commented 3 years ago

https://github.com/rubenlagus/TelegramBots/blob/4882040822d202e146471d6196e3a40babbdb51a/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java#L664

When handling replies,I often get an error with a message: "Reply [null] failed to check for conditions. Make sure you're safeguarding against all possible updates.".

This message does not provide any useful information on what happened. I suggest adding also an error message and the stack to the logged info. So the message could provide more valuable information for solving the issue.

Kr1SEl commented 2 months ago

I found a workaround for this moment, maybe it would help someone. Based on the code of the method 'runSilently' - it would show you an error message if slf4j Logger is in the Debug mode.

boolean runSilently(Callable<Boolean> callable, String name) {
        try {
            return (Boolean)callable.call();
        } catch (Exception var5) {
            Exception ex = var5;
            String msg = String.format("Reply [%s] failed to check for conditions. Make sure you're safeguarding against all possible updates.", name);
            if (log.isDebugEnabled()) {
                log.error(msg, ex);
            } else {
                log.error(msg);
            }

            return false;
        }
    }

In order to turn it on we could add a slf4j configuration file to the 'src/main/resources' directory named 'logback-spring.xml'

Here is an example of such file:

<configuration>
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
    <include resource="org/springframework/boot/logging/logback/console-appender.xml"/>

    <!-- Set the root logger level to DEBUG -->
    <root level="DEBUG">
        <appender-ref ref="CONSOLE"/>
    </root>

    <!-- Set the logger level for your specific package -->
    <logger name="org.kris.evermeet_telegram" level="DEBUG"/>
</configuration>

Unfortunately, it generates an enormous amount of useless logs and shouldn't be enabled forever, but it's still a good way to reproduce the error and check what exactly went wrong.

rubenlagus commented 2 months ago

That can be added to the bot implementer code directly instead of library enforcing a debug level of logging