mirror of https://gitlab.com/KKlochko/tui-rsync
parent
a4a0f32f52
commit
769edabbd3
@ -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
|
@ -0,0 +1,3 @@
|
||||
from .exception_helpers import catch_exception
|
||||
|
||||
__all__ = ['catch_exception']
|
@ -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
|
Loading…
Reference in new issue