/
exc.py
39 lines (28 loc) · 1.03 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
"""Exceptions for libvcs."""
from typing import Optional, Union
class LibVCSException(Exception):
"""Standard exception raised by libvcs."""
class CommandError(LibVCSException):
"""This exception is raised on non-zero return codes."""
def __init__(
self,
output: str,
returncode: Optional[int] = None,
cmd: Optional[Union[str, list[str]]] = None,
) -> None:
self.returncode = returncode
self.output = output
if cmd:
if isinstance(cmd, list):
cmd = " ".join(cmd)
self.cmd = cmd
def __str__(self) -> str:
message = self.message.format(returncode=self.returncode, cmd=self.cmd)
if len(self.output.strip()):
message += "\n%s" % self.output
return message
message = "Command failed with code {returncode}: {cmd}"
class CommandTimeoutError(CommandError):
"""CommandError which gets raised when a subprocess exceeds its timeout."""
class InvalidVCS(LibVCSException):
"""Invalid VCS."""