Skip to content
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

fix(api): add supported wavelengths to runtime error when initializing the plate reader. #16797

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading