Skip to content

Commit

Permalink
fix(api): add supported wavelengths to runtime error when initializin…
Browse files Browse the repository at this point in the history
…g the plate reader. (#16797)
  • Loading branch information
vegano1 authored Nov 14, 2024
1 parent 6d62bec commit 0ae0414
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from ..command import AbstractCommandImpl, BaseCommand, BaseCommandCreate, SuccessData
from ...errors.error_occurrence import ErrorOccurrence
from ...errors import InvalidWavelengthError

if TYPE_CHECKING:
from opentrons.protocol_engine.state.state import StateView
Expand Down Expand Up @@ -69,30 +70,41 @@ async def execute(self, params: InitializeParams) -> SuccessData[InitializeResul
unsupported_wavelengths = sample_wavelengths.difference(
supported_wavelengths
)
sample_wl_str = ", ".join([str(w) + "nm" for w in sample_wavelengths])
supported_wl_str = ", ".join([str(w) + "nm" for w in supported_wavelengths])
unsupported_wl_str = ", ".join(
[str(w) + "nm" for w in unsupported_wavelengths]
)
if unsupported_wavelengths:
raise ValueError(f"Unsupported wavelengths: {unsupported_wavelengths}")
raise InvalidWavelengthError(
f"Unsupported wavelengths: {unsupported_wl_str}. "
f" Use one of {supported_wl_str} instead."
)

if params.measureMode == "single":
if sample_wavelengths_len != 1:
raise ValueError(
f"single requires one sample wavelength, provided {sample_wavelengths}"
f"Measure mode `single` requires one sample wavelength,"
f" {sample_wl_str} provided instead."
)
if (
reference_wavelength is not None
and reference_wavelength not in supported_wavelengths
):
raise ValueError(
f"Reference wavelength {reference_wavelength} not supported {supported_wavelengths}"
raise InvalidWavelengthError(
f"Reference wavelength {reference_wavelength}nm is not supported."
f" Use one of {supported_wl_str} instead."
)

if params.measureMode == "multi":
if sample_wavelengths_len < 1 or sample_wavelengths_len > 6:
raise ValueError(
f"multi requires 1-6 sample wavelengths, provided {sample_wavelengths}"
f"Measure mode `multi` requires 1-6 sample wavelengths,"
f" {sample_wl_str} provided instead."
)
if reference_wavelength is not None:
raise RuntimeError(
"Reference wavelength cannot be used with multi mode."
raise ValueError(
"Reference wavelength cannot be used with Measure mode `multi`."
)

await abs_reader.set_sample_wavelength(
Expand Down
2 changes: 2 additions & 0 deletions api/src/opentrons/protocol_engine/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
InvalidTargetTemperatureError,
InvalidBlockVolumeError,
InvalidHoldTimeError,
InvalidWavelengthError,
CannotPerformModuleAction,
PauseNotAllowedError,
ResumeFromRecoveryNotAllowedError,
Expand Down Expand Up @@ -137,6 +138,7 @@
"InvalidTargetSpeedError",
"InvalidBlockVolumeError",
"InvalidHoldTimeError",
"InvalidWavelengthError",
"CannotPerformModuleAction",
"ResumeFromRecoveryNotAllowedError",
"PauseNotAllowedError",
Expand Down
13 changes: 13 additions & 0 deletions api/src/opentrons/protocol_engine/errors/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,19 @@ def __init__(
super().__init__(ErrorCodes.GENERAL_ERROR, message, details, wrapping)


class InvalidWavelengthError(ProtocolEngineError):
"""Raised when attempting to set an invalid absorbance wavelength."""

def __init__(
self,
message: Optional[str] = None,
details: Optional[Dict[str, Any]] = None,
wrapping: Optional[Sequence[EnumeratedError]] = None,
) -> None:
"""Build a InvalidWavelengthError."""
super().__init__(ErrorCodes.GENERAL_ERROR, message, details, wrapping)


class InvalidHoldTimeError(ProtocolEngineError):
"""An error raised when attempting to set an invalid temperature hold time."""

Expand Down

0 comments on commit 0ae0414

Please sign in to comment.