/
exc.py
132 lines (96 loc) · 3.45 KB
/
exc.py
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""Exceptions for tmuxp."""
import typing as t
from libtmux._internal.query_list import ObjectDoesNotExist
from ._compat import implements_to_string
class TmuxpException(Exception):
"""Base Exception for Tmuxp Errors."""
class WorkspaceError(TmuxpException):
"""Error parsing tmuxp workspace data."""
class SessionNotFound(TmuxpException):
"""tmux session not found."""
def __init__(
self,
session_target: t.Optional[str] = None,
*args: object,
**kwargs: object,
) -> None:
msg = "Session not found"
if session_target is not None:
msg += f": {session_target}"
return super().__init__(msg, *args, **kwargs)
class WindowNotFound(TmuxpException):
"""tmux window not found."""
def __init__(
self,
window_target: t.Optional[str] = None,
*args: object,
**kwargs: object,
) -> None:
msg = "Window not found"
if window_target is not None:
msg += f": {window_target}"
return super().__init__(msg, *args, **kwargs)
class PaneNotFound(TmuxpException):
"""tmux pane not found."""
def __init__(
self,
pane_target: t.Optional[str] = None,
*args: object,
**kwargs: object,
) -> None:
msg = "Pane not found"
if pane_target is not None:
msg += f": {pane_target}"
return super().__init__(msg, *args, **kwargs)
class EmptyWorkspaceException(WorkspaceError):
"""Workspace file is empty."""
def __init__(
self,
*args: object,
**kwargs: object,
) -> None:
return super().__init__("Session configuration is empty.", *args, **kwargs)
class SessionMissingWorkspaceException(WorkspaceError, ObjectDoesNotExist):
"""Session missing while loading tmuxp workspace."""
def __init__(self, *args: object, **kwargs: object) -> None:
return super().__init__(
"No session object exists for WorkspaceBuilder. "
"Tip: Add session_name in constructor or run WorkspaceBuilder.build()",
*args,
**kwargs,
)
class ActiveSessionMissingWorkspaceException(WorkspaceError):
"""Active session cannot be found while loading tmuxp workspace."""
def __init__(self, *args: object, **kwargs: object) -> None:
return super().__init__("No session active.", *args, **kwargs)
class TmuxpPluginException(TmuxpException):
"""Base Exception for Tmuxp Errors."""
class BeforeLoadScriptNotExists(OSError):
"""Raises if shell script could not be found."""
def __init__(self, *args: object, **kwargs: object) -> None:
super().__init__(*args, **kwargs)
self.strerror = f"before_script file '{self.strerror}' doesn't exist."
@implements_to_string
class BeforeLoadScriptError(Exception):
"""Shell script execution error.
Replaces :py:class:`subprocess.CalledProcessError` for
:meth:`tmuxp.util.run_before_script`.
"""
def __init__(
self,
returncode: int,
cmd: str,
output: t.Optional[str] = None,
) -> None:
self.returncode = returncode
self.cmd = cmd
self.output = output
self.message = (
f"before_script failed with returncode {self.returncode}.\n"
f"command: {self.cmd}\n"
"Error output:\n"
f"{self.output}"
)
def __str__(self) -> str:
"""Return shell error message."""
return self.message