telegram-bot-bash icon indicating copy to clipboard operation
telegram-bot-bash copied to clipboard

send_* fuctions' return value

Open enamp opened this issue 2 years ago • 2 comments

Hi Almost all send_* and some other functions from sendMessage.sh are returning non-zero values after successfull execution It breaks sometest && send_* || handle_error scenario I have 2 options to solve it:

  1. add || return 0 to all affected lines: [ -n "${BOTSENT[ERROR]}" ] && processError $ARGS || return 0
  2. rewrite error test statement to [ ! -n "${BOTSENT[ERROR]}" ] ||

enamp avatar Jan 24 '22 12:01 enamp

for historical reason the return value for send functions are undefined and later on I added the telegram response to allow checking the telegram response.

I understand it would be better to return a defined return value, let me think about, but it's hard to enshure that the value is correct in all cases as bash return the value of the last exected command.

therefore you always have to check BOTSENT[] values in your script to know what's returned from telegram.

nevertheless I'll think about to improve the situation.

gnadelwartz avatar Jan 26 '22 08:01 gnadelwartz

Thinking more about, currently a non zero return value means bashbot think there is something wrong with your arguments or an internal error happend. a zero return value means nothing bad happend "arguments seems ok and sent to telegram". In theory it should work like this:

if send_xxx then
    # sent to telegram, check telegram response
    echo "Telegram response BOTSENT[*]"
else
   # not sent to telegram, may be wromng argumrents or internal error
   echo "Ups, something wrong"
fi

# or like this
if send_xxx && -n "$[BOTSENT[ERROR]"; then
   echo "Sent to telegram, response: BOTSENT[*]"
fi

but yes it's not perfect :-) and currntly does not work ... I'll try to imporove it in future

gnadelwartz avatar Jan 26 '22 09:01 gnadelwartz