Commit 0bf3201f authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[decorators] Add returned value to error message of of raise_on_error

parent c8f13748
...@@ -40,7 +40,7 @@ from functools import wraps ...@@ -40,7 +40,7 @@ from functools import wraps
from .log import set_verbosity_level from .log import set_verbosity_level
# This needs to be beat so that logger is configured for all beat packages. # This needs to be beat so that logger is configured for all beat packages.
logger = logging.getLogger('beat') logger = logging.getLogger("beat")
def verbosity_option(**kwargs): def verbosity_option(**kwargs):
...@@ -56,20 +56,28 @@ def verbosity_option(**kwargs): ...@@ -56,20 +56,28 @@ def verbosity_option(**kwargs):
callable callable
A decorator to be used for adding this option. A decorator to be used for adding this option.
""" """
def custom_verbosity_option(f): def custom_verbosity_option(f):
def callback(ctx, param, value): def callback(ctx, param, value):
ctx.meta['verbosity'] = value ctx.meta["verbosity"] = value
set_verbosity_level(logger, value) set_verbosity_level(logger, value)
logger.debug("Logging of the `beat' logger was set to %d", value) logger.debug("Logging of the `beat' logger was set to %d", value)
return value return value
return click.option( return click.option(
'-v', '--verbose', count=True, "-v",
expose_value=False, default=2, "--verbose",
count=True,
expose_value=False,
default=2,
help="Increase the verbosity level from 0 (only error messages) " help="Increase the verbosity level from 0 (only error messages) "
"to 1 (warnings), 2 (log messages), 3 (debug information) by " "to 1 (warnings), 2 (log messages), 3 (debug information) by "
"adding the --verbose option as often as desired " "adding the --verbose option as often as desired "
"(e.g. '-vvv' for debug).", "(e.g. '-vvv' for debug).",
callback=callback, **kwargs)(f) callback=callback,
**kwargs
)(f)
return custom_verbosity_option return custom_verbosity_option
...@@ -83,8 +91,11 @@ def raise_on_error(view_func): ...@@ -83,8 +91,11 @@ def raise_on_error(view_func):
def _decorator(*args, **kwargs): def _decorator(*args, **kwargs):
value = view_func(*args, **kwargs) value = view_func(*args, **kwargs)
if value not in [None, 0]: if value not in [None, 0]:
exception = click.ClickException("Error occured") exception = click.ClickException(
"Error occured: returned value is {}".format(value)
)
exception.exit_code = value exception.exit_code = value
raise exception raise exception
return value return value
return wraps(view_func)(_decorator) return wraps(view_func)(_decorator)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment