Debian Codegraph @

lib/ansible/_internal/_errors/_captured.py

raw
1 from __future__ import annotations
2
3 import dataclasses
4 import typing as t
5
6 from ansible._internal._errors import _error_utils
7 from ansible.errors import AnsibleRuntimeError
8 from ansible.module_utils._internal import _messages
9
10 if t.TYPE_CHECKING:
11 from ansible._internal import _task
12
13
14 class AnsibleCapturedError(AnsibleRuntimeError):
15 """An exception representing error detail captured in another context where the error detail must be serialized to be preserved."""
16
17 context: str
18
19 def __init__(
20 self,
21 *,
22 obj: t.Any = None,
23 event: _messages.Event,
24 ) -> None:
25 super().__init__(
26 obj=obj,
27 )
28
29 self._event = event
30
31
32 class AnsibleResultCapturedError(AnsibleCapturedError, _error_utils.ContributesToTaskResult):
33 """
34 An exception representing error detail captured in a foreign context where an action/module result dictionary is involved.
35
36 This exception provides a result dictionary via the ContributesToTaskResult mixin.
37 """
38
39 def __init__(self, event: _messages.Event, utr: _task.UnifiedTaskResult) -> None:
40 self.context = utr._captured_error_context
41 self._default_message = utr._captured_error_message
42
43 super().__init__(event=event)
44
45 self._utr = utr
46
47 def as_task_result(self, utr: _task.UnifiedTaskResult) -> _task.UnifiedTaskResult:
48 return self._utr # RPFIX-5: DOC: explain this better - Drop the provided UTR on the floor and use the stored one instead.
49
50
51 @dataclasses.dataclass(**_messages._dataclass_kwargs)
52 class CapturedErrorSummary(_messages.ErrorSummary):
53 # RPFIX-5: DOC: clean this up (naming, docstring, etc.)
54 error_message: str
55 error_context: str
56 is_module: bool