def cli_endpoint(fn):
    '\n    Decorator for command line endpoints that execute dags or tasks. It runs\n    the decorated function, captures exception (if any), sends a colored\n    traceback to standard error and exits with code 1.\n\n    Notes\n    -----\n    Functions decorated with this must be called with keyword arguments\n\n    Call some_endpoint(catch_exception=False) to disable this behavior (e.g.\n    for testing)\n    '

    @wraps(fn)
    def wrapper(catch_exception=True, **kwargs):
        if catch_exception:
            try:
                fn(**kwargs)
            except (DAGBuildError, DAGRenderError):
                error = traceback.format_exc()
                color = False
            except Exception:
                error = traceback.format_exc()
                color = True
            else:
                error = None
            if error:
                if color:
                    tw = TerminalWriter(file=sys.stderr)
                    tw._write_source(error.splitlines())
                else:
                    print(error, file=sys.stderr)
                sys.exit(1)
        else:
            fn(**kwargs)
    return wrapper
Decorator for command line endpoints that execute dags or tasks. It runs
the decorated function, captures exception (if any), sends a colored
traceback to standard error and exits with code 1.

Notes
-----
Functions decorated with this must be called with keyword arguments

Call some_endpoint(catch_exception=False) to disable this behavior (e.g.
for testing)
def cli_endpoint(fn):
    '\n    Decorator for command line endpoints that execute dags or tasks. It runs\n    the decorated function, captures exception (if any), sends a colored\n    traceback to standard error and exits with code 1.\n\n    Notes\n    -----\n    Functions decorated with this must be called with keyword arguments\n\n    Call some_endpoint(catch_exception=False) to disable this behavior (e.g.\n    for testing)\n    '

    @wraps(fn)
    def wrapper(catch_exception=True, **kwargs):
        if catch_exception:
            try:
                fn(**kwargs)
            except (DAGBuildError, DAGRenderError):
                error = traceback.format_exc()
                color = False
            except Exception:
                error = traceback.format_exc()
                color = True
            else:
                error = None
            if error:
                if color:
                    tw = TerminalWriter(file=sys.stderr)
                    tw._write_source(error.splitlines())
                else:
                    print(error, file=sys.stderr)
                sys.exit(1)
        else:
            fn(**kwargs)
    return wrapper