zephyr_mirror: Improve zwrite error handling.
(imported from commit a6b5b9c0c9bd6ffde0b2b783c87528bdcae03566)
This commit is contained in:
parent
5689e99a0d
commit
5411e5c360
|
@ -337,9 +337,14 @@ def send_zephyr(zwrite_args, content):
|
||||||
if p.returncode:
|
if p.returncode:
|
||||||
print "zwrite command '%s' failed with return code %d:" % (
|
print "zwrite command '%s' failed with return code %d:" % (
|
||||||
" ".join(zwrite_args), p.returncode,)
|
" ".join(zwrite_args), p.returncode,)
|
||||||
|
if stdout:
|
||||||
print stdout
|
print stdout
|
||||||
|
elif stderr:
|
||||||
|
print "zwrite command '%s' printed the following warning:" % (
|
||||||
|
" ".join(zwrite_args),)
|
||||||
|
if stderr:
|
||||||
print stderr
|
print stderr
|
||||||
return p.returncode
|
return (p.returncode, stderr)
|
||||||
|
|
||||||
def send_authed_zephyr(zwrite_args, content):
|
def send_authed_zephyr(zwrite_args, content):
|
||||||
return send_zephyr(zwrite_args, content)
|
return send_zephyr(zwrite_args, content)
|
||||||
|
@ -390,34 +395,50 @@ def forward_to_zephyr(message):
|
||||||
(zwrite_args, wrapped_content.encode("utf-8")))
|
(zwrite_args, wrapped_content.encode("utf-8")))
|
||||||
return
|
return
|
||||||
|
|
||||||
if send_authed_zephyr(zwrite_args, wrapped_content) != 0:
|
heading = "Hi there! This is an automated message from Humbug."
|
||||||
# If your tickets have expired, Humbug users got your zephyr but MIT
|
support_closing = """If you have any questions, please be in touch through the \
|
||||||
# zephyr users didn't. Try to re-send unauthed, and send a Humbug
|
Feedback tab or at support@humbughq.com."""
|
||||||
# notifying the user that they should check their tickets/mirror.
|
|
||||||
error_msg = """Hi there! This is an automated message from Humbug.
|
(code, stderr) = send_authed_zephyr(zwrite_args, wrapped_content)
|
||||||
|
if code == 0 and stderr == "":
|
||||||
|
return
|
||||||
|
elif code == 0:
|
||||||
|
return send_error_humbug("""%s
|
||||||
|
|
||||||
|
Your last message was successfully mirrored to zephyr, but zwrite \
|
||||||
|
returned the following warning:
|
||||||
|
|
||||||
%s
|
%s
|
||||||
|
|
||||||
If you have any questions, please be in touch through the Feedback tab or at \
|
%s""" % (heading, stderr, support_closing))
|
||||||
support@humbughq.com."""
|
elif code != 0 and (stderr.startswith("zwrite: Ticket expired while sending notice to ") or
|
||||||
if send_unauthed_zephyr(zwrite_args, wrapped_content) != 0:
|
stderr.startswith("zwrite: No credentials cache found while sending notice to ")):
|
||||||
error_msg_detail = """\
|
# Retry sending the message unauthenticated; if that works,
|
||||||
Your Humbug-Zephyr mirror bot was unable to forward that last message \
|
# just notify the user that they need to renew their tickets
|
||||||
from Humbug to Zephyr. That means that while Humbug users (like you) \
|
(code, stderr) = send_unauthed_zephyr(zwrite_args, wrapped_content)
|
||||||
received it, Zephyr users did not.
|
if code == 0:
|
||||||
|
return send_error_humbug("""%s
|
||||||
|
|
||||||
Please check that /mit/tabbott/humbug/zephyr_mirror.py is still \
|
|
||||||
running and that you have valid Kerberos tickets, and then you can \
|
|
||||||
resend your message if you would still like it to be mirrored.
|
|
||||||
"""
|
|
||||||
else:
|
|
||||||
error_msg_detail = """\
|
|
||||||
Your last message was forwarded from Humbug to Zephyr unauthenticated, \
|
Your last message was forwarded from Humbug to Zephyr unauthenticated, \
|
||||||
because your Kerberos tickets have expired. It was sent successfully, \
|
because your Kerberos tickets have expired. It was sent successfully, \
|
||||||
but please renew your Kerberos tickets in the screen session where you \
|
but please renew your Kerberos tickets in the screen session where you \
|
||||||
are running the Humbug-Zephyr mirroring bot, so we can send \
|
are running the Humbug-Zephyr mirroring bot, so we can send \
|
||||||
authenticated Zephyr messages for you again."""
|
authenticated Zephyr messages for you again.
|
||||||
send_error_humbug(error_msg % (error_msg_detail,))
|
|
||||||
|
%s""" % (heading, support_closing))
|
||||||
|
|
||||||
|
# zwrite failed and it wasn't because of expired tickets: This is
|
||||||
|
# probably because the recipient isn't subscribed to personals,
|
||||||
|
# but regardless, we should just notify the user.
|
||||||
|
return send_error_humbug("""%s
|
||||||
|
|
||||||
|
Your Humbug-Zephyr mirror bot was unable to forward that last message \
|
||||||
|
from Humbug to Zephyr. That means that while Humbug users (like you) \
|
||||||
|
received it, Zephyr users did not. The error message from zwrite was:
|
||||||
|
|
||||||
|
%s
|
||||||
|
|
||||||
|
%s""" % (heading, stderr, support_closing))
|
||||||
|
|
||||||
def maybe_forward_to_zephyr(message):
|
def maybe_forward_to_zephyr(message):
|
||||||
if (message["sender_email"] == options.user + "@mit.edu"):
|
if (message["sender_email"] == options.user + "@mit.edu"):
|
||||||
|
|
Loading…
Reference in a new issue