Improved error messages in clan_cli

This commit is contained in:
Qubasa
2024-01-19 14:10:22 +01:00
parent 01a61f778b
commit 154bdc384f
2 changed files with 9 additions and 7 deletions

View File

@@ -139,11 +139,10 @@ def main() -> None:
sys.exit(1) sys.exit(1)
if isinstance(e, ClanCmdError): if isinstance(e, ClanCmdError):
if e.cmd.msg: if e.cmd.msg:
print(e.cmd.msg, file=sys.stderr) log.error(e.cmd.msg)
else: sys.exit(1)
print(e, file=sys.stderr)
elif isinstance(e, ClanError): log.error(e)
print(e, file=sys.stderr)
sys.exit(1) sys.exit(1)

View File

@@ -22,7 +22,7 @@ def get_formatter(color: str) -> Callable[[logging.LogRecord, bool], logging.For
return logging.Formatter(f"{color}%(levelname)s{reset}: %(message)s") return logging.Formatter(f"{color}%(levelname)s{reset}: %(message)s")
return logging.Formatter( return logging.Formatter(
f"{color}%(levelname)s{reset}: %(message)s\n {filepath}:%(lineno)d::%(funcName)s\n" f"{color}%(levelname)s{reset}: %(message)s\n {filepath}:%(lineno)d::%(funcName)s\n"
) )
return myformatter return myformatter
@@ -39,7 +39,10 @@ FORMATTER = {
class CustomFormatter(logging.Formatter): class CustomFormatter(logging.Formatter):
def format(self, record: logging.LogRecord) -> str: def format(self, record: logging.LogRecord) -> str:
return FORMATTER[record.levelno](record, True).format(record) if record.levelno == logging.DEBUG:
return FORMATTER[record.levelno](record, True).format(record)
else:
return FORMATTER[record.levelno](record, False).format(record)
class ThreadFormatter(logging.Formatter): class ThreadFormatter(logging.Formatter):