File: exceptions.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (115 lines) | stat: -rw-r--r-- 4,026 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from typing import TYPE_CHECKING, Any, Optional

from moto.core.exceptions import JsonRESTError

if TYPE_CHECKING:
    from .models.generic_type import GenericType


class SWFClientError(JsonRESTError):
    code = 400


class SWFUnknownResourceFault(SWFClientError):
    def __init__(self, resource_type: str, resource_name: Optional[str] = None):
        if resource_name:
            message = f"Unknown {resource_type}: {resource_name}"
        else:
            message = f"Unknown {resource_type}"
        super().__init__("com.amazonaws.swf.base.model#UnknownResourceFault", message)


class SWFDomainAlreadyExistsFault(SWFClientError):
    def __init__(self, domain_name: str):
        super().__init__(
            "com.amazonaws.swf.base.model#DomainAlreadyExistsFault", domain_name
        )


class SWFDomainDeprecatedFault(SWFClientError):
    def __init__(self, domain_name: str):
        super().__init__(
            "com.amazonaws.swf.base.model#DomainDeprecatedFault", domain_name
        )


class SWFSerializationException(SWFClientError):
    def __init__(self, value: Any):
        message = "class java.lang.Foo can not be converted to an String "
        message += f" (not a real SWF exception ; happened on: {value})"
        __type = "com.amazonaws.swf.base.model#SerializationException"
        super().__init__(__type, message)


class SWFTypeAlreadyExistsFault(SWFClientError):
    def __init__(self, _type: "GenericType"):
        super().__init__(
            "com.amazonaws.swf.base.model#TypeAlreadyExistsFault",
            f"{_type.__class__.__name__}=[name={_type.name}, version={_type.version}]",
        )


class SWFTypeDeprecatedFault(SWFClientError):
    def __init__(self, _type: "GenericType"):
        super().__init__(
            "com.amazonaws.swf.base.model#TypeDeprecatedFault",
            f"{_type.__class__.__name__}=[name={_type.name}, version={_type.version}]",
        )


class SWFWorkflowExecutionAlreadyStartedFault(SWFClientError):
    def __init__(self) -> None:
        super().__init__(
            "com.amazonaws.swf.base.model#WorkflowExecutionAlreadyStartedFault",
            "Already Started",
        )


class SWFDefaultUndefinedFault(SWFClientError):
    def __init__(self, key: str):
        # TODO: move that into moto.core.utils maybe?
        words = key.split("_")
        key_camel_case = words.pop(0)
        for word in words:
            key_camel_case += word.capitalize()
        super().__init__(
            "com.amazonaws.swf.base.model#DefaultUndefinedFault", key_camel_case
        )


class SWFValidationException(SWFClientError):
    def __init__(self, message: str):
        super().__init__("com.amazon.coral.validate#ValidationException", message)


class SWFDecisionValidationException(SWFClientError):
    def __init__(self, problems: list[dict[str, Any]]):
        # messages
        messages = []
        for pb in problems:
            if pb["type"] == "null_value":
                messages.append(
                    f"Value null at '{pb['where']}' failed to satisfy constraint: Member must not be null"
                )
            elif pb["type"] == "bad_decision_type":
                messages.append(
                    f"Value '{pb['value']}' at '{pb['where']}' failed to satisfy constraint: "
                    f"Member must satisfy enum value set: [{pb['possible_values']}]"
                )
            else:
                raise ValueError(f"Unhandled decision constraint type: {pb['type']}")
        # prefix
        count = len(problems)
        if count < 2:
            prefix = "{0} validation error detected: "
        else:
            prefix = "{0} validation errors detected: "
        super().__init__(
            "com.amazon.coral.validate#ValidationException",
            prefix.format(count) + "; ".join(messages),
        )


class SWFWorkflowExecutionClosedError(Exception):
    def __str__(self) -> str:
        return repr("Cannot change this object because the WorkflowExecution is closed")