in bonsaicli2/bonsai_cli/utils.py [0:0]
def raise_as_click_exception(*args: Any):
"""This function raises a ClickException with a message that contains
the specified message and the details of the specified exception.
This is useful for all of our commands to raise errors to the
user in a consistent way.
This function expects to be handed an Exception (or
one of its subclasses), or a message string followed by an Exception.
"""
try:
config = Config(argv=sys.argv, use_aad=False)
color = config.use_color
except ValueError:
color = False
if args and len(args) == 1:
raise CustomClickException(
"An error occurred\n" "{}".format(str(args[0])), color=color
)
elif args and len(args) > 1:
raise CustomClickException("{}\n{}".format(args[0], args[1]), color=color)
else:
raise CustomClickException("An error occurred", color=color)