clan-core/pkgs/clan-cli/clan_cli/errors.py
Qubasa 359275eee7
All checks were successful
checks-impure / test (pull_request) Successful in 1m18s
checks / test (pull_request) Successful in 2m50s
Improved error message. Fixed incorrect ret code check in git.py
2024-01-10 18:54:34 +01:00

53 lines
1.0 KiB
Python

from pathlib import Path
from typing import NamedTuple
class CmdOut(NamedTuple):
stdout: str
stderr: str
cwd: Path
command: str
returncode: int
def __str__(self) -> str:
return f"""
Working Directory: '{self.cwd}'
Return Code: {self.returncode}
=================== Command ===================
{self.command}
=================== STDERR ===================
{self.stderr}
=================== STDOUT ===================
{self.stdout}
"""
class ClanError(Exception):
"""Base class for exceptions in this module."""
pass
class ClanHttpError(ClanError):
status_code: int
msg: str
def __init__(self, status_code: int, msg: str) -> None:
self.status_code = status_code
self.msg = msg
super().__init__(msg)
class ClanCmdError(ClanError):
cmd: CmdOut
def __init__(self, cmd: CmdOut) -> None:
self.cmd = cmd
super().__init__()
def __str__(self) -> str:
return str(self.cmd)
def __repr__(self) -> str:
return f"ClanCmdError({self.cmd})"