-
Notifications
You must be signed in to change notification settings - Fork 377
Expand file tree
/
Copy patherror.py
More file actions
29 lines (24 loc) · 885 Bytes
/
error.py
File metadata and controls
29 lines (24 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import typing as t
import logging
from functools import wraps
import click
import sys
logger = logging.getLogger(__name__)
def cli_global_error_handler(
func: t.Callable[..., t.Any],
) -> t.Callable[..., t.Any]:
@wraps(func)
def wrapper(*args: t.List[t.Any], **kwargs: t.Any) -> t.Any:
try:
return func(*args, **kwargs)
except Exception as ex:
# these imports are deliberately deferred to avoid the penalty of importing the `sqlmesh`
# package up front for every CLI command
from sqlmesh.utils.errors import SQLMeshError
from sqlglot.errors import SqlglotError
if isinstance(ex, (SQLMeshError, SqlglotError, ValueError)):
click.echo(click.style("Error: " + str(ex), fg="red"))
sys.exit(1)
else:
raise
return wrapper