Skip to content

Commit

Permalink
Merge pull request #205 from lsst-sqre/tickets/DM-45138
Browse files Browse the repository at this point in the history
DM-45138: Make InvalidCutoutParametersError generic
  • Loading branch information
rra authored Jul 12, 2024
2 parents c46eff0 + c6b36b3 commit de2b36c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
17 changes: 0 additions & 17 deletions src/vocutouts/exceptions.py

This file was deleted.

11 changes: 5 additions & 6 deletions src/vocutouts/models/cutout.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
field_validator,
)

from ..exceptions import InvalidCutoutParameterError
from ..uws.config import ParametersModel
from ..uws.exceptions import MultiValuedParameterError
from ..uws.exceptions import MultiValuedParameterError, ParameterParseError
from ..uws.models import UWSJobParameter
from .domain.cutout import (
WorkerCircleStencil,
Expand Down Expand Up @@ -223,11 +222,11 @@ def from_job_parameters(cls, params: list[UWSJobParameter]) -> Self:
Raises
------
InvalidCutoutParameterError
Raised if one of the parameters could not be parsed.
MultiValuedParameterError
Raised if more than one dataset ID or more than one stencil is
provided.
ParameterParseError
Raised if one of the parameters could not be parsed.
"""
ids = []
stencils = []
Expand All @@ -241,7 +240,7 @@ def from_job_parameters(cls, params: list[UWSJobParameter]) -> Self:
stencils.append(stencil)
except Exception as e:
msg = f"Invalid cutout parameter: {type(e).__name__}: {e!s}"
raise InvalidCutoutParameterError(msg, params) from e
raise ParameterParseError(msg, params) from e

# For now, only support a single ID and stencil. These have to be
# checked outside of the validator because the SODA standard requires
Expand All @@ -254,7 +253,7 @@ def from_job_parameters(cls, params: list[UWSJobParameter]) -> Self:
try:
return cls(ids=ids, stencils=stencils)
except ValidationError as e:
raise InvalidCutoutParameterError(str(e), params) from e
raise ParameterParseError(str(e), params) from e

def to_worker_parameters(self) -> WorkerCutout:
"""Convert to the domain model used by the backend worker."""
Expand Down
18 changes: 12 additions & 6 deletions src/vocutouts/uws/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
"""Exceptions for the Universal Worker Service.
The types of exceptions here control the error handling behavior configured in
:py:mod:`vocutouts.uws.errors`.
"""
"""Exceptions for the Universal Worker Service."""

from __future__ import annotations

Expand All @@ -19,14 +15,15 @@
)
from safir.slack.webhook import SlackIgnoredException

from .models import ErrorCode, ErrorType, UWSJobError
from .models import ErrorCode, ErrorType, UWSJobError, UWSJobParameter
from .uwsworker import WorkerError, WorkerErrorType

__all__ = [
"DataMissingError",
"InvalidPhaseError",
"MultiValuedParameterError",
"ParameterError",
"ParameterParseError",
"PermissionDeniedError",
"SyncJobFailedError",
"SyncJobNoResultsError",
Expand Down Expand Up @@ -262,6 +259,15 @@ class ParameterError(UsageError):
"""Unsupported value passed to a parameter."""


class ParameterParseError(ParameterError):
"""UWS job parameters could not be parsed."""

def __init__(self, message: str, params: list[UWSJobParameter]) -> None:
detail = "\n".join(f"{p.parameter_id}={p.value}" for p in params)
super().__init__(message, detail)
self.params = params


class UnknownJobError(DataMissingError):
"""The named job could not be found in the database."""

Expand Down

0 comments on commit de2b36c

Please sign in to comment.