File: errors.py

package info (click to toggle)
shadow 1%3A4.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 66,920 kB
  • sloc: sh: 44,121; ansic: 34,155; xml: 12,285; exp: 3,691; makefile: 1,650; python: 1,135; perl: 120; sed: 16
file content (42 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import annotations


class ExpectScriptError(Exception):
    """
    Expect script error.

    Seeing this exception means that there is an unhandled path or other error
    in the expect script that was executed. The script needs to be fixed.
    """

    def __init__(self, code: int, msg: str | None = None) -> None:
        """
        :param code: Expect script error code.
        :type code: int
        :param msg: Error message, defaults to None (translate error code to message)
        :type msg: str | None, optional
        """
        self.code: int = code
        if msg is None:
            msg = self.code_to_message(code)

        super().__init__(msg)

    def code_to_message(self, code: int) -> str:
        """
        Translate expect script error codes used in this framework to message.

        :param code: Expect script error code.
        :type code: int
        :return: Error message.
        :rtype: str
        """
        match code:
            case 201:
                return "Timeout, unexpected output"
            case 202:
                return "Unexpected end of file"
            case 203:
                return "Unexpected code path"

        return "Unknown error code"