Skip to content

Commit

Permalink
Fold Missing* error into InvalidCorrelationIdError
Browse files Browse the repository at this point in the history
  • Loading branch information
TheByronHimes authored and TheByronHimes committed Dec 1, 2023
1 parent 9850d8f commit 9fc6cc6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
15 changes: 3 additions & 12 deletions src/hexkit/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"new_correlation_id",
"validate_correlation_id",
"CorrelationIdContextError",
"MissingCorrelationIdError",
"InvalidCorrelationIdError",
]

Expand All @@ -50,10 +49,6 @@ def __init__(self, *, correlation_id: str):
super().__init__(message)


class MissingCorrelationIdError(RuntimeError):
"""Raised when a correlation ID is not supplied."""


def new_correlation_id() -> str:
"""Generates a new correlation ID."""
return str(uuid4())
Expand All @@ -63,7 +58,7 @@ def validate_correlation_id(correlation_id: str):
"""Raises an error if the correlation ID is invalid.
Raises:
InvalidCorrelationIdError: If the correlation ID is invalid.
InvalidCorrelationIdError: If the correlation ID is empty or invalid.
"""
try:
UUID(correlation_id)
Expand All @@ -76,12 +71,8 @@ async def set_correlation_id(correlation_id: str):
"""Set the correlation ID for the life of the context.
Raises:
InvalidCorrelationIdError: when the correlation ID is set but invalid.
MissingCorrelationIdError: when the correlation ID arg is empty.
InvalidCorrelationIdError: when the correlation ID is empty or invalid.
"""
if not correlation_id:
raise MissingCorrelationIdError()

validate_correlation_id(correlation_id)

async with set_context_var(correlation_id_var, correlation_id):
Expand All @@ -96,7 +87,7 @@ def get_correlation_id() -> str:
Raises:
CorrelationIdContextError: when the correlation ID ContextVar is not set.
InvalidCorrelationIdError: when the correlation ID is set but invalid.
InvalidCorrelationIdError: when the correlation ID is invalid.
"""
if not (correlation_id := correlation_id_var.get()):
raise CorrelationIdContextError()
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from hexkit.correlation import (
CorrelationIdContextError,
InvalidCorrelationIdError,
MissingCorrelationIdError,
correlation_id_var,
get_correlation_id,
new_correlation_id,
Expand Down Expand Up @@ -86,7 +85,7 @@ async def test_correlation_id_validation(correlation_id: str, exception):
"correlation_id,exception",
[
("12345", InvalidCorrelationIdError),
("", MissingCorrelationIdError),
("", InvalidCorrelationIdError),
(new_correlation_id(), None),
],
)
Expand Down

0 comments on commit 9fc6cc6

Please sign in to comment.