mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-08-12 09:47:44 +00:00
Add the exceptions and helpers.
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
from .app_exception import AppException
|
||||
from .command_exception import CommandException
|
||||
|
||||
__all__ = ['AppException', 'CommandException']
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
class AppException(Exception):
|
||||
pass
|
||||
@@ -0,0 +1,6 @@
|
||||
from . import AppException
|
||||
|
||||
|
||||
class CommandException(AppException):
|
||||
"""Command failed to change persistence data."""
|
||||
pass
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
from .exception_helpers import catch_exception
|
||||
|
||||
__all__ = ['catch_exception']
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
from functools import wraps
|
||||
|
||||
import typer
|
||||
from rich.console import Console
|
||||
|
||||
|
||||
def catch_exception(which_exception, exit_code=1):
|
||||
def decorator(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except which_exception as e:
|
||||
console = Console()
|
||||
console.print(f'[red b][ERROR] {str(e)}[/]')
|
||||
raise typer.Exit(code=exit_code)
|
||||
return wrapper
|
||||
return decorator
|
||||
Reference in New Issue
Block a user