halig/halig/utils.py
cătălin bdb5c984fa
All checks were successful
checks / pre-commit (push) Successful in 1m39s
checks / tests-10 (push) Successful in 1m17s
checks / tests-11 (push) Successful in 1m10s
checks / tests-12 (push) Successful in 1m13s
ci: add pre-commit and tests workflows
2024-08-04 15:23:55 +02:00

32 lines
737 B
Python

import sys
from collections.abc import Callable
from functools import wraps
from rich import print
from whenever import Instant
def now():
return Instant.now()
def now_as_date():
return now().py_datetime().date()
def capture(fn: Callable):
@wraps(fn)
def wrapper(*args, **kwargs):
try:
return fn(*args, **kwargs)
except OSError as exc:
print(f"[red]{exc.strerror} on {exc.filename or exc.filename2}")
sys.exit(exc.errno)
except ValueError as exc:
print(f"[red]{exc}")
sys.exit(1)
except Exception as exc: # noqa: BLE001
print(f"[bold red] Unexpected error: {exc}")
sys.exit(2)
return wrapper