From 0556b3043ced278f8930de747cf4071f728e1e11 Mon Sep 17 00:00:00 2001 From: Leo Dirac Date: Tue, 13 Feb 2024 15:33:59 -0800 Subject: [PATCH] Better error messages in CLI. Catching another edge case with a helpful error. --- src/groundlight/cli.py | 4 ++-- src/groundlight/client.py | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/groundlight/cli.py b/src/groundlight/cli.py index 059d34e6..bf380bef 100644 --- a/src/groundlight/cli.py +++ b/src/groundlight/cli.py @@ -55,8 +55,8 @@ def groundlight(): cli_func = class_func_to_cli(method) cli_app.command()(cli_func) cli_app() - except ApiTokenError: - print(API_TOKEN_MISSING_HELP_MESSAGE) + except ApiTokenError as e: + print(e) if __name__ == "__main__": diff --git a/src/groundlight/client.py b/src/groundlight/client.py index 87ca7d56..5bddb004 100644 --- a/src/groundlight/client.py +++ b/src/groundlight/client.py @@ -107,12 +107,14 @@ def __init__( self.endpoint = sanitize_endpoint_url(endpoint) configuration = Configuration(host=self.endpoint) - if api_token is None: + if not api_token: try: # Retrieve the API token from environment variable api_token = os.environ[API_TOKEN_VARIABLE_NAME] except KeyError as e: raise ApiTokenError(API_TOKEN_MISSING_HELP_MESSAGE) from e + if not api_token: + raise ApiTokenError("No API token found. GROUNDLIGHT_API_TOKEN environment variable is set but blank") self.api_token_prefix = api_token[:12] should_disable_tls_verification = disable_tls_verification