Skip to content

zulip: Reraise exceptions in do_api_query. #735

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

Merged
merged 2 commits into from
Feb 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 24 additions & 21 deletions zulip/zulip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import traceback
import types
import urllib.parse
from configparser import SafeConfigParser
from configparser import ConfigParser
from typing import (
IO,
Any,
Expand Down Expand Up @@ -425,9 +425,9 @@ def __init__(
config_file = get_default_config_filename()

if config_file is not None and os.path.exists(config_file):
config = SafeConfigParser()
config = ConfigParser()
with open(config_file) as f:
config.readfp(f, config_file)
config.read_file(f, config_file)
if api_key is None:
api_key = config.get("api", "key")
if email is None:
Expand Down Expand Up @@ -681,10 +681,7 @@ def end_error_retry(succeeded: bool) -> None:
continue
else:
end_error_retry(False)
return {
"msg": f"Connection error:\n{traceback.format_exc()}",
"result": "connection-error",
}
raise
except requests.exceptions.ConnectionError:
if not self.has_connected:
# If we have never successfully connected to the server, don't
Expand All @@ -696,16 +693,10 @@ def end_error_retry(succeeded: bool) -> None:
if error_retry(""):
continue
end_error_retry(False)
return {
"msg": f"Connection error:\n{traceback.format_exc()}",
"result": "connection-error",
}
raise
except Exception:
# We'll split this out into more cases as we encounter new bugs.
return {
"msg": f"Unexpected error:\n{traceback.format_exc()}",
"result": "unexpected-error",
}
raise

try:
if requests_json_is_function:
Expand Down Expand Up @@ -782,16 +773,28 @@ def do_register() -> Tuple[str, int]:
if queue_id is None:
(queue_id, last_event_id) = do_register()

res = self.get_events(queue_id=queue_id, last_event_id=last_event_id)
try:
res = self.get_events(queue_id=queue_id, last_event_id=last_event_id)
except (
requests.exceptions.Timeout,
requests.exceptions.SSLError,
requests.exceptions.ConnectionError,
):
if self.verbose:
print(f"Connection error fetching events:\n{traceback.format_exc()}")
# TODO: Make this use our backoff library
time.sleep(1)
continue
except Exception:
print(f"Unexpected error:\n{traceback.format_exc()}")
# TODO: Make this use our backoff library
time.sleep(1)
continue

if "error" in res["result"]:
if res["result"] == "http-error":
if self.verbose:
print("HTTP error fetching events -- probably a server restart")
elif res["result"] == "connection-error":
if self.verbose:
print(
"Connection error fetching events -- probably server is temporarily down?"
)
else:
if self.verbose:
print("Server returned error:\n{}".format(res["msg"]))
Expand Down