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

Logging and logical improvements for test_connection decorator #2999

Merged
merged 4 commits into from
Feb 17, 2025
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
28 changes: 19 additions & 9 deletions augur/application/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import json
import httpx
import traceback

from augur.application.db.engine import DatabaseEngine
from augur.application.db import get_engine, dispose_database_engine
Expand All @@ -16,23 +17,32 @@ def test_connection(function_internet_connection):
@click.pass_context
def new_func(ctx, *args, **kwargs):
usage = re.search(r"Usage:\s(.*)\s\[OPTIONS\]", str(ctx.get_usage())).groups()[0]
success = False
with httpx.Client() as client:
try:
_ = client.request(
method="GET", url="http://chaoss.community", timeout=10, follow_redirects=True)

return ctx.invoke(function_internet_connection, *args, **kwargs)
success = True
except (TimeoutError, httpx.TimeoutException):
print("Request timed out.")
except httpx.NetworkError:
except httpx.NetworkError as e:
print(f"Network Error: {httpx.NetworkError}")
except httpx.ProtocolError:
print(traceback.format_exc())
except httpx.ProtocolError as e:
print(f"Protocol Error: {httpx.ProtocolError}")
print(f"\n\n{usage} command setup failed\n \
You are not connected to the internet.\n \
Please connect to the internet to run Augur\n \
Consider setting http_proxy variables for limited access installations.")
sys.exit(-1)
print(traceback.format_exc())

if not success:
print(
f"""
\n\n{usage} command setup failed.
There was an error while testing for network connectivity
Please check your connection to the internet to run Augur
Consider setting http_proxy variables for limited access installations."""
)
sys.exit(-1)

return ctx.invoke(function_internet_connection, *args, **kwargs)

return update_wrapper(new_func, function_internet_connection)

Expand Down
Loading