Skip to content

Commit

Permalink
Fail user friendly if Snowflake server is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
buremba committed Aug 5, 2024
1 parent ab08137 commit 3d87058
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions universql/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import requests
import uvicorn
import yaml
from requests.exceptions import SSLError

from universql.util import LOCALHOST_UNIVERSQL_COM_BYTES, Compute, Catalog, sizeof_fmt

Expand Down Expand Up @@ -62,9 +63,16 @@ def snowflake(host, port, ssl_keyfile, ssl_certfile, account, catalog, compute,
v is not None and k not in ["host", "port"]}
auto_catalog_mode = catalog is None
if auto_catalog_mode:
polaris_server_check = requests.get(
f"https://{account}.snowflakecomputing.com/polaris/api/catalog/v1/oauth/tokens")
is_polaris = polaris_server_check.status_code == 405
try:
polaris_server_check = requests.get(
f"https://{account}.snowflakecomputing.com/polaris/api/catalog/v1/oauth/tokens")
is_polaris = polaris_server_check.status_code == 405
except SSLError as e:
error_message = (f"Unable to find Snowflake account (https://{account}.snowflakecomputing.com), make sure if you have access to the Snowflake account. (maybe need VPN access?) \n"
f"You can set `--catalog` property to avoid this error. \n {str(e.args[0])}")
logger.error(error_message)
sys.exit(1)

context__params["catalog"] = Catalog.POLARIS.value if is_polaris else Catalog.SNOWFLAKE.value

if context__params["catalog"] == Catalog.POLARIS.value:
Expand Down

0 comments on commit 3d87058

Please sign in to comment.