Exemple #1
0
    def _add_last_error_info(self, exc_info=None):
        ex = exc_info[1]

        if show_exc_info(ex):
            # if we are showing internal task - we don't know how to "minimize" stack.
            # everything is databand.* ...
            isolate = not self.task.task_definition.full_task_family.startswith(
                "databand.")
            traceback_str = self.settings.log.format_exception_as_str(
                exc_info=exc_info, isolate=isolate)

            self.banner.column(
                colored("TRACEBACK", color="red", attrs=["bold"]),
                traceback_str,
                raw_name=True,
            )

        self.banner.column(
            colored("ERROR MESSAGE", color="red", attrs=["bold"]),
            str(ex),
            raw_name=True,
        )

        self.banner.column(
            colored("HELP", attrs=["bold"]),
            get_help_msg(ex),
            raw_name=True,
            skip_if_empty=True,
        )
        self.banner.column(
            colored("CAUSED BY", color="red", attrs=["bold"]),
            nested_exceptions_str(ex, limit=3),
            raw_name=True,
            skip_if_empty=True,
        )
Exemple #2
0
 def as_error_info(self):
     ex = self.exception
     task = self.task_run.task
     isolate = not task.task_definition.full_task_family.startswith(
         "databand.")
     return ErrorInfo(
         msg=str(ex),
         help_msg=get_help_msg(ex),
         exc_type=self.exc_info[0],
         databand_error=isinstance(ex, DatabandError),
         nested=nested_exceptions_str(ex, limit=1),
         traceback=self.traceback,
         user_code_traceback=task.settings.log.format_exception_as_str(
             exc_info=self.exc_info, isolate=isolate),
         show_exc_info=bool(show_exc_info(ex)),
     )
Exemple #3
0
def get_databand_error_message(ex, args=None, sys_exit=True):
    args = args or sys.argv
    please_report = False
    print_source = True

    if isinstance(ex, DatabandRunError):
        # we already printed all information!
        return (
            "There is an error! Your run has failed!",
            DatabandExitCodes.execution_failed,
        )

    if isinstance(ex, DatabandRuntimeError):
        exit_code = DatabandExitCodes.execution_failed
    elif isinstance(ex, DatabandConfigError):
        exit_code = DatabandExitCodes.configuration_error
    elif isinstance(ex, DatabandSystemError):
        exit_code = DatabandExitCodes.error
        please_report = True
    elif isinstance(ex, DatabandError):
        exit_code = DatabandExitCodes.error
    elif ex.__class__.__name__ == "NoCredentialsError":  # aws
        exit_code = DatabandExitCodes.configuration_error
        ex = friendly_error.config.no_credentials()
        print_source = False
    else:
        please_report = True
        exit_code = DatabandExitCodes.unknown_error

    msg = str(ex)

    extra_msg_lines = []

    nested_exceptions = nested_exceptions_str(ex)
    if nested_exceptions:
        extra_msg_lines.append("Caused by: \n%s\n" %
                               indent(nested_exceptions, "\t"))

    help_msg = get_help_msg(ex)
    if help_msg:
        extra_msg_lines.append(" Help: \n%s\n" % indent(help_msg, "\t"))

    user_frame_info_str = get_user_frame_info_str(ex)
    if user_frame_info_str and print_source:
        extra_msg_lines.append("Source: \n%s\n" %
                               indent(user_frame_info_str, "\t"))

    # if we crashed before finishing bootstrap we probably want to see the full trace, and we could have failed during config init so the verbose flag does nothing
    if (show_exc_info(ex) or config.getboolean("databand", "verbose")
            or not bootstrap._dbnd_bootstrap):
        error_info = sys.exc_info()
        extra_msg_lines.append(format_exception_as_str(error_info))

    msg = truncate_msg(msg, ERROR_MESSAGE_HEAD_SIZE, ERROR_MESSAGE_TAIL_SIZE)

    if please_report:
        extra_msg_lines.append(
            " Please report it to [email protected] or appropriate slack channel!"
        )
    msg = ("There is an error! Your run has failed with {exc_type}\n"
           "{sep}\n"
           " Command line: {command_line}\n"
           " Failure:\n{msg}\n\n"
           "{extra_msg}\n"
           "{sep}\n"
           "".format(
               sep=console_utils.error_separator(),
               command_line=subprocess.list2cmdline(args or []),
               sep_small=console_utils.error_separator_small(),
               msg=console_utils.bold(indent(msg, "\t")),
               exc_type=ex.__class__.__name__,
               extra_msg="\n ".join(extra_msg_lines),
           ))
    return msg, exit_code