diff --git a/CHANGELOG.md b/CHANGELOG.md index a2f03f33..e104bafa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added docstrings to logging methods ([#40](https://github.com/neptune-ai/neptune-client-scale/pull/40)) +- Dedicated exceptions for missing project or API token ([#44](https://github.com/neptune-ai/neptune-client-scale/pull/44)) ### Changed - Removed `timestamp` parameter from `add_tags()`, `remove_tags()` and `log_configs()` methods ([#37](https://github.com/neptune-ai/neptune-client-scale/pull/37)) diff --git a/src/neptune_scale/__init__.py b/src/neptune_scale/__init__.py index 6014cab4..2bc91f16 100644 --- a/src/neptune_scale/__init__.py +++ b/src/neptune_scale/__init__.py @@ -61,6 +61,10 @@ API_TOKEN_ENV_NAME, PROJECT_ENV_NAME, ) +from neptune_scale.exceptions import ( + NeptuneApiTokenNotProvided, + NeptuneProjectNotProvided, +) from neptune_scale.parameters import ( MAX_EXPERIMENT_NAME_LENGTH, MAX_FAMILY_LENGTH, @@ -167,12 +171,14 @@ def __init__( raise ValueError("`max_queue_size` must be greater than 0.") project = project or os.environ.get(PROJECT_ENV_NAME) - verify_non_empty("project", project) + if project is None: + raise NeptuneProjectNotProvided() assert project is not None # mypy input_project: str = project api_token = api_token or os.environ.get(API_TOKEN_ENV_NAME) - verify_non_empty("api_token", api_token) + if api_token is None: + raise NeptuneApiTokenNotProvided() assert api_token is not None # mypy input_api_token: str = api_token diff --git a/src/neptune_scale/exceptions.py b/src/neptune_scale/exceptions.py index d9584c06..389eb1e2 100644 --- a/src/neptune_scale/exceptions.py +++ b/src/neptune_scale/exceptions.py @@ -34,6 +34,8 @@ "NeptuneStringSetExceedsSizeLimit", "NeptuneSynchronizationStopped", "NeptuneAsyncLagThresholdExceeded", + "NeptuneProjectNotProvided", + "NeptuneApiTokenNotProvided", ) from typing import Any @@ -492,3 +494,35 @@ class NeptuneAsyncLagThresholdExceeded(NeptuneScaleError): Struggling with the formatting? To disable it, set the `NEPTUNE_DISABLE_COLORS` environment variable to `True`. """ + + +class NeptuneProjectNotProvided(NeptuneRetryableError): + message = """ +{h1} +----NeptuneProjectNotProvided-------------------------------------------------- +{end} +The project name was not provided. Make sure to specify the project name in the `project` parameter of the `Run` +constructor or with the `NEPTUNE_PROJECT` environment variable. + +For instructions, see https://docs-beta.neptune.ai/setup + +{correct}Need help?{end}-> Contact support@neptune.ai + +Struggling with the formatting? To disable it, set the `NEPTUNE_DISABLE_COLORS` environment variable to `True`. +""" + + +class NeptuneApiTokenNotProvided(NeptuneRetryableError): + message = """ +{h1} +----NeptuneApiTokenNotProvided------------------------------------------------- +{end} +The Neptune API token was not provided. Make sure to specify the API token in the `api_token` parameter of the `Run` +constructor or with the `NEPTUNE_API_TOKEN` environment variable. + +For instructions, see https://docs-beta.neptune.ai/api_token + +{correct}Need help?{end}-> Contact support@neptune.ai + +Struggling with the formatting? To disable it, set the `NEPTUNE_DISABLE_COLORS` environment variable to `True`. +"""