Skip to content

chore: Dedicated exceptions for lack of project or api token #44

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 5 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 8 additions & 2 deletions src/neptune_scale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
30 changes: 30 additions & 0 deletions src/neptune_scale/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"NeptuneStringSetExceedsSizeLimit",
"NeptuneSynchronizationStopped",
"NeptuneAsyncLagThresholdExceeded",
"NeptuneProjectNotProvided",
"NeptuneApiTokenNotProvided",
)

from typing import Any
Expand Down Expand Up @@ -492,3 +494,31 @@ 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 `NEPTUNE_PROJECT` environment variable.

{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 api token was not provided. Make sure to specify the api token in the `api_token` parameter of the `Run`
constructor or with `NEPTUNE_API_TOKEN` environment variable.

{correct}Need help?{end}-> Contact support@neptune.ai

Struggling with the formatting? To disable it, set the `NEPTUNE_DISABLE_COLORS` environment variable to `True`.
"""
Loading