mirror of
https://gitlab.com/KKlochko/tui-rsync.git
synced 2026-08-12 17:57:43 +00:00
Add the exceptions and helpers.
This commit is contained in:
+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