Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send_* fuctions' return value #190

Open
enamp opened this issue Jan 24, 2022 · 2 comments
Open

send_* fuctions' return value #190

enamp opened this issue Jan 24, 2022 · 2 comments

Comments

@enamp
Copy link
Contributor

enamp commented Jan 24, 2022

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]}" ] ||
@gnadelwartz
Copy link
Collaborator

gnadelwartz commented Jan 26, 2022

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
Copy link
Collaborator

gnadelwartz commented Jan 26, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants