def show(self, file=None): if file is None: file = get_text_stderr() if self.ctx: color = self.ctx.color echo(self.ctx.get_help(), file=file, color=color) secho('Error: %s' % self.format_message(), file=file, fg="red")
def show(self, file=None): # ping matomo about error ping_matomo("/error?message=%s" % self.message) # continue from click._compat import get_text_stderr if file is None: file = get_text_stderr() # echo wrap color = 'red' import click def echo(message): # from click.utils import echo # echo('Error: %s' % self.format_message(), file=file, color=color) click.secho(message, fg=color) # main error echo('Error: %s' % self.format_message()) # if isitfit installation is outdated, append a message to upgrade if self.ctx is not None: if self.ctx.obj.get('is_outdated', None): hint_1 = "Upgrade your isitfit installation with `pip3 install --upgrade isitfit` and try again." echo(hint_1) # add link to github issues hint_2 = "If the problem persists, please report it at https://github.com/autofitcloud/isitfit/issues/new" echo(hint_2)
def show(self, file=None): if file is None: from click._compat import get_text_stderr file = get_text_stderr() click.secho('!! Configuration error: %s' % self.format_message(), file=file, fg='red')
def show(self, file=None): """Override default `show` to print CLI errors in red text.""" if file is None: file = get_text_stderr() click.secho("Error: {}".format(self.format_message()), file=file, fg="red") if self.help: click.echo(self.help, err=True)
def show(self, file=None): if file is None: file = get_text_stderr() context.io.echo("Error: %s" % (self.format_message(), ), file=file) context.io.echo(traceback.format_exc(), verbosity=context.io.DETAIL, file=file)
def show(self, file=None): if file is None: from click._compat import get_text_stderr file = get_text_stderr() click.secho("!! Configuration error: %s" % six.text_type(self), file=file, fg="red")
def show(self, file=None): if file is None: file = get_text_stderr() click.secho('Error: %s' % self.format_message(), file=file, fg=self.fg, bg=self.bg, bold=self.bold)
def show(self, file=None): if file is None: file = get_text_stderr() click.echo(click.style("[!] Error Running Command", fg="red", bold=True), err=True) click.echo("") click.echo(self.format_message(), file=file, err=True)
def _show_usage_error(self, file=None): if file is None: file = get_text_stderr() color = None echo('Error: %s' % self.format_message(), file=file, color=color) if self.ctx is not None: echo('', file=file) color = self.ctx.color echo(self.ctx.get_help() + '\n', file=file, color=color)
def show(self, file=None): import sys if file is None: file = get_text_stderr() if self.ctx is not None: color = self.ctx.color echo(self.ctx.get_usage() + '\n', file=file, color=color) echo_error(self.format_message(), file=file) sys.argv = [sys.argv[0]]
def show(self, file=None): # ping matomo about error from isitfit.utils import ping_matomo ping_matomo("/error?message=%s"%self.message) # continue from click._compat import get_text_stderr if file is None: file = get_text_stderr() # echo wrap color = 'red' def wrapecho(message): # from click.utils import echo # echo('Error: %s' % self.format_message(), file=file, color=color) click.secho(message, fg=color) # main error wrapecho('Error: %s' % self.format_message()) # if error from terminal during execution (not on program boot) if self.ctx is not None: if self.ctx.obj is not None: # if isitfit installation is outdated, append a message to upgrade if self.ctx.obj.get('is_outdated', None): hint_1 = "Upgrade your isitfit installation with `pip3 install --upgrade isitfit` and try again." wrapecho(hint_1) # test that boto3 minimum command can run # This would fail for example for: `AWS_ACCESS_KEY_ID=wrong AWS_SECRET_ACCESS_KEY=alsowrong aws iam get-user` import boto3 iam_client = boto3.client('iam') try: # response = iam_client.get_user() iam_client.get_user() except Exception as e: msg_e = str(e) hint_3 = f"""Hint: The command `aws iam get-user` has also failed with the following error: {msg_e} This might indicate a problem with your aws user's permissions and could be related to the current error in isitfit.""" # Update 2020-01-09 Instead of raising an exception, just display a warning #from isitfit.cli.click_descendents import IsitfitCliError #raise IsitfitCliError(hint_3) from e # ping matomo about warning from isitfit.utils import ping_matomo ping_matomo("/warning/aws-iam-get-user?message=%s"%hint_3) # display on screen wrapecho(hint_3) # add link to github issues hint_2 = "Is this my fault? 😞 Please report it at https://github.com/autofitcloud/isitfit/issues/new or reach out to me at [email protected]" wrapecho(hint_2)
def show(self, file: Optional[str] = None): """ Override ClickException function show() to print in color """ if file is None: file = get_text_stderr() if self.color: click.secho( 'Error: %s' % self.format_message(), file=file, fg='red') else: click.echo('Error: %s' % self.format_message(), file=file)
def show(self, file: Any = None) -> None: if file is None: file = get_text_stderr() click.echo( "Jira REST API Error ({0} {1}):\n{2} ".format( self.status_code, responses[self.status_code], self.format_message()), file=file, )
def show(self, file=None): if file is None: file = get_text_stderr() if "--no-color" in sys.argv or "-nc" in sys.argv: echo(click.style("[x]") + click.style(u' %s' % text(self.format_message())), file=file) else: echo(click.style("[x]", bg="red") + click.style(u' %s' % text(self.format_message()), fg="red"), file=file)
def show(self, file=None): import sys if file is None: file = get_text_stderr() color = None if self.ctx is not None: color = self.ctx.color echo(self.ctx.get_usage() + '\n', file=file, color=color) echo('Error: %s\n' % self.format_message(), file=file, color=color) sys.argv = [sys.argv[0]] main_command()
def show(self, file=None, **styles): if file is None: file = get_text_stderr() if (self.cmd is not None and self.cmd.get_help_option(self.ctx) is not None): hint = ('Try "%s %s" for help. \n' % (self.ctx.command_path, self.ctx.help_option_names[0])) secho('Error: %s' % self.format_message(), file=file, fg='red', bold=True)
def show(self, file=None): if file is None: file = get_text_stderr() color = None hint = '' if (self.cmd is not None and self.cmd.get_help_option(self.ctx) is not None): hint = ('Try "%s %s" for help.\n' % (self.ctx.command_path, self.ctx.help_option_names[0])) if self.ctx is not None: color = self.ctx.color click.echo(self.ctx.get_usage() + '\n%s' % hint, file=file, color=color) msg = colorama.Fore.RED + 'Error: %s' % self.format_message() + colorama.Style.RESET_ALL click.echo(msg, file=file, color=color)
def show(self, file=None): tcfcli.common.operation_msg.Operation(self.format_message(), level="ERROR").no_output() if file is None: file = get_text_stderr() if "--no-color" in sys.argv or "-nc" in sys.argv: echo(click.style("[x]") + click.style(u' %s' % text(self.format_message())), file=file) else: echo(click.style("[x] [ERROR] ", bg="red") + click.style(u' %s' % text(self.format_message()), fg="red"), file=file)
def log(self, level, msg, *args, **kwargs): if args and kwargs: raise TypeError( "You may give positional or keyword arguments, not both") args = args or kwargs # render if args: rendered = msg % args else: rendered = msg # output if level >= self.level: color = self.COLORS.get(level) stream = get_text_stderr() if level >= self.WARNING else None click.secho(rendered, file=stream, fg=color)
def log(self, level, msg, *args, **kwargs): if args: if kwargs: raise TypeError( "You may give positional or keyword arguments, not both") args = args or kwargs # render if args: rendered = msg % args else: rendered = msg # output if level >= self.level: color = self.COLORS.get(level) stream = get_text_stderr() if level >= self.WARNING else None click.secho(rendered, file=stream, fg=color)
def invoke_(self, arg): try: # Invoke the command cmd.main(args=shlex.split(arg), prog_name=cmd.name, standalone_mode=False, parent=self.ctx) except click.UsageError as e: # Shows the usage subclass error message file = get_text_stderr() color = None hint = "" if e.cmd is not None and e.cmd.get_help_option(e.ctx) is not None: hint = "\tTry '{} {}' for help.\n".format( e.ctx.command_path, e.ctx.help_option_names[0]) if e.ctx is not None: print() color = e.ctx.color click.echo("\t{}\n{}".format(e.ctx.get_usage(), hint), file=file, color=color) click.echo("\t{err_color}Error: {msg}{reset}".format( err_color=colors.USAGE_ERROR_STYLE, reset=Style.RESET_ALL, msg=e.format_message()), file=file) except click.ClickException as e: # Shows the standard click exception message file = get_text_stderr() click.echo("\t{err_color}Error: {msg}{reset}".format( err_color=colors.CLICK_ERROR_STYLE, reset=Style.RESET_ALL, msg=e.format_message()), file=file) except click.Abort: # An EOF or KeyboardInterrupt was returned # Raise as a new KeyboardInterrupt click.echo(file=self._stdout) raise KeyboardInterrupt() except SystemExit: # Ignore system exit from click pass except Exception as e: # Catch and pretty-format a Python Exception caught from the click command formatter = click.HelpFormatter(4, 128, 128) formatter.indent() formatter.write_text('{}An unexpected error has occurred{}'.format( colors.UNEXPECTED_ERROR_TEXT_STYLE, Style.RESET_ALL)) formatter.write_paragraph() with formatter.section( '{fore}{back}{style}Python Trace{reset}'.format( fore=colors.PYTHON_ERROR_HEADER_FORE, back=colors.PYTHON_ERROR_HEADER_BACK, style=colors.PYTHON_ERROR_HEADER_STYLE, reset=Style.RESET_ALL)): formatter.write(colors.PYTHON_STACKTRACE_STYLE) formatter.write_text(''.join( traceback.format_exception(type(e), e, None))) if globs.SHOW_STACKTRACE: formatter.write_text('\n'.join( traceback.format_exception(*sys.exc_info())[:-1])) formatter.write(Style.RESET_ALL) click.echo(formatter.getvalue()) logger.warning(traceback.format_exc()) # Do not allow shell to exit return False
def show(self, file=None): if file is None: file = get_text_stderr() echo(self.format_message(), file=file)
def show(self, file=None): """Exclude 'Error:' prefix from raised exceptions.""" if file is None: file = get_text_stderr() echo(self.format_message())
def show(self, file=None): if file is None: file = get_text_stderr() echo(click.style("[x]", bg="red") + click.style(u' %s' % text(self.format_message()), fg="red"), file=file)
def show(self, file: Optional[Any] = None) -> None: """Show error message.""" if file is None: file = get_text_stderr() error = click.style("Error", fg="red") click.echo(f"{error}: {self.format_message()}", file=file)
def show(self, file=None): if file is None: from click._compat import get_text_stderr file = get_text_stderr() click.secho(f"!! Configuration error: {self!r}", file=file, fg="red")
def _do_deploy_core(self, func, func_name, func_ns, region, forced, success_list, faild_list, skip_event=False): # check role exit try: role = func.get(tsmacro.Properties, {}).get(tsmacro.Role) if role: rolelist = list_scf_role(region) if rolelist == None: Operation("Get Role list error").warning() func[tsmacro.Properties][tsmacro.Role] = None elif role not in rolelist: Operation("%s not exists in remote scf role list" % (role)).warning() if len(rolelist): Operation("You can choose from %s " % (str(rolelist))).warning() func[tsmacro.Properties][tsmacro.Role] = None # check namespace exit, create namespace if self.namespace and self.namespace != func_ns: func_ns = self.namespace function_data = Function(region, func_ns, func_name, self.resources).get_function_trigger() trigger_release = None if function_data: now_runtime = function_data[0] trigger_release = function_data[1] if func['Properties']['Runtime'] != now_runtime: err_msg = "RUNTIME in YAML does not match RUNTIME on the RELEASE (release: %s)" % now_runtime echo( Operation("[x]", bg="red").style() + Operation(u' %s' % text(err_msg), fg="red").style(), file=get_text_stderr() ) exit(1) # raise DeployException(err_msg) rep = ScfClient(region).get_ns(func_ns) if not rep: Operation("{ns} not exists, create it now".format(ns=func_ns)).process() err = ScfClient(region).create_ns(func_ns) if err is not None: if sys.version_info[0] == 3: s = err.get_message() else: s = err.get_message().encode("UTF-8") err_msg = "Create namespace '{name}' failure. Error: {e}.".format(name=func_ns, e=s) echo( Operation("[x]", bg="red").style() + Operation(u' %s' % text(err_msg), fg="red").style(), file=get_text_stderr() ) exit(1) # raise NamespaceException() deploy_result = ScfClient(region).deploy_func(func, func_name, func_ns, forced) if deploy_result == 1: Operation("{ns} {name} already exists, update it now".format(ns=func_ns, name=func_name)).process() deploy_result = ScfClient(region).update_config(func, func_name, func_ns) if deploy_result == True: deploy_result = ScfClient(region).update_code(func, func_name, func_ns) deploy_result = 0 if deploy_result == True else deploy_result if deploy_result == 0: Operation("Deploy function '{name}' success".format(name=func_name)).success() if not skip_event: self._do_deploy_trigger(func, func_name, func_ns, region, trigger_release) success_list.append(func_name) return elif deploy_result == 2: faild_list.append(func_name) Operation( "%s %s: You can add -f to update the function when it already exists. Example : scf deploy -f" % ( func_ns, func_name)).warning() err_msg = "%s %s: The function already exists." % (func_ns, func_name) echo( Operation("[x]", bg="red").style() + Operation(u' %s' % text(err_msg), fg="red").style(), file=get_text_stderr() ) exit(1) # raise CloudAPIException("The function already exists.") if deploy_result != None: faild_list.append(func_name) err = deploy_result s = err.get_message() if sys.version_info[0] == 2 and isinstance(s, str): s = s.encode("utf8") err_msg = u"Deploy function '{name}' failure, {e}.".format(name=func_name, e=s) if err.get_request_id(): err_msg += (u" RequestId: {}".format(err.get_request_id())) echo( Operation("[x]", bg="red").style() + Operation(u' %s' % text(err_msg), fg="red").style(), file=get_text_stderr() ) exit(1) # raise CloudAPIException(err_msg) except Exception as e: faild_list.append(func_name) echo( Operation("[x]", bg="red").style() + Operation(u' %s' % text(str(e)), fg="red").style(), file=get_text_stderr() ) exit(1)
def show(self, file: t.Optional[t.IO] = None) -> None: if file is None: file = get_text_stderr() message = _build_message(self) echo(_("Error: {message}").format(message=message), file=file)