Skip to content

Exceptions

pychilaslasers.exceptions

PyChilasLasers exceptions module.

This module contains all custom exceptions for the PyChilasLasers library. These exceptions provide specific error handling for laser operations and modes.

Authors: SDU

Modules:

  • laser_error

    Class representing errors received from the laser.

  • mode_error

    Exception class for laser mode-related errors.

Classes:

Classes

LaserError(code: str, message: str)

Bases: Exception

Parameters:

  • code (str) –

    The error code sent by the laser. Typically a 1 but kept abstract to allow for future expansion.

  • message (str) –

    The error message.

Source code in src/pychilaslasers/exceptions/laser_error.py
 8
 9
10
11
12
13
14
15
16
17
18
def __init__(self, code: str, message: str) -> None:
    """Class representing errors received from the laser.

    Args:
        code (str): The error code sent by the laser. Typically a 1 but kept
            abstract to allow for future expansion.
        message (str): The error message.

    """
    self.code: str = code
    self.message: str = message
Functions

ModeError(message: str, current_mode: LaserMode | Mode, desired_mode: LaserMode | Mode | None = None)

Bases: Exception

Exception raised for errors related to the laser mode.

This exception is used to indicate that an operation cannot be performed in the current mode of the laser. It provides information about the current mode and the desired mode that would allow the operation to succeed

Parameters:

  • message (str) –

    The error message.

  • current_mode (LaserMode) –

    The current mode of the laser.

  • desired_mode (LaserMode | None, default: None ) –

    The laser mode that would allow for the operation to succeed. Defaults to None.

Source code in src/pychilaslasers/exceptions/mode_error.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def __init__(
    self,
    message: str,
    current_mode: LaserMode | Mode,
    desired_mode: LaserMode | Mode | None = None,
) -> None:
    """Exception raised in case of an error related to the mode the laser is in.

    This exception is used to indicate that an operation cannot be performed
    in the current mode of the laser.
    It provides information about the current mode and the desired mode that would
    allow the operation to succeed

    Args:
        message (str): The error message.
        current_mode (LaserMode): The current mode of the laser.
        desired_mode (LaserMode | None, optional): The laser mode that would allow
            for the operation to succeed. Defaults to None.

    """
    super().__init__(message)
    self.message: str = message

    # Checking to allow for the use of both LaserMode and Mode types
    self.current_mode: LaserMode = (
        current_mode if isinstance(current_mode, LaserMode) else current_mode.mode
    )
    self.desired_mode: LaserMode | None = (
        desired_mode
        if isinstance(desired_mode, LaserMode)
        else (desired_mode.mode if desired_mode is not None else None)
    )
    # Constructing the error message
    if self.desired_mode:
        self.message += (
            f" (current mode: {self.current_mode.name}, mode this"
            + f" operation is possible in: {self.desired_mode.name})"
        )
    else:
        self.message += f" (current mode: {self.current_mode.name})"
Functions