2024-01-10 16:58:39 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from typing import NamedTuple
|
|
|
|
|
|
|
|
|
|
|
|
class CmdOut(NamedTuple):
|
|
|
|
stdout: str
|
|
|
|
stderr: str
|
|
|
|
cwd: Path
|
|
|
|
command: str
|
|
|
|
returncode: int
|
2024-01-10 18:29:16 +00:00
|
|
|
msg: str | None = None
|
2024-01-10 16:58:39 +00:00
|
|
|
|
2024-01-10 17:54:34 +00:00
|
|
|
def __str__(self) -> str:
|
|
|
|
return f"""
|
2024-01-10 18:29:16 +00:00
|
|
|
Message: {self.msg}
|
2024-01-10 17:54:34 +00:00
|
|
|
Working Directory: '{self.cwd}'
|
|
|
|
Return Code: {self.returncode}
|
|
|
|
=================== Command ===================
|
|
|
|
{self.command}
|
|
|
|
=================== STDERR ===================
|
|
|
|
{self.stderr}
|
|
|
|
=================== STDOUT ===================
|
|
|
|
{self.stdout}
|
|
|
|
"""
|
|
|
|
|
2024-01-10 16:58:39 +00:00
|
|
|
|
2023-07-26 13:50:27 +00:00
|
|
|
class ClanError(Exception):
|
|
|
|
"""Base class for exceptions in this module."""
|
|
|
|
|
|
|
|
pass
|
2023-11-21 13:34:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ClanHttpError(ClanError):
|
|
|
|
status_code: int
|
|
|
|
msg: str
|
|
|
|
|
2023-11-30 12:42:15 +00:00
|
|
|
def __init__(self, status_code: int, msg: str) -> None:
|
2023-11-21 13:34:31 +00:00
|
|
|
self.status_code = status_code
|
|
|
|
self.msg = msg
|
|
|
|
super().__init__(msg)
|
2024-01-10 16:58:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ClanCmdError(ClanError):
|
|
|
|
cmd: CmdOut
|
|
|
|
|
|
|
|
def __init__(self, cmd: CmdOut) -> None:
|
|
|
|
self.cmd = cmd
|
|
|
|
super().__init__()
|
2024-01-10 17:54:34 +00:00
|
|
|
|
|
|
|
def __str__(self) -> str:
|
|
|
|
return str(self.cmd)
|
|
|
|
|
|
|
|
def __repr__(self) -> str:
|
|
|
|
return f"ClanCmdError({self.cmd})"
|