def _nested_exceptions_messages(ex, limit=None, current=""): nested_exceptions = getattr(ex, "nested_exceptions", []) if limit: limit -= 1 messages = [] from dbnd._core.utils.basics.helpers import indent for idx, cur_ex in enumerate(nested_exceptions, start=1): if cur_ex is None: continue ex_id = "{current}{idx}".format(current=current, idx=idx) message = "{ex_id}. {ex_type}: {msg} ".format( ex_id=ex_id, ex_type=type(cur_ex).__name__, msg=str(cur_ex)) help_msg = get_help_msg(cur_ex) if help_msg: message += "\n{help_msg}".format( help_msg=indent(help_msg, " " * len(ex_id))) user_frame_info_str = get_user_frame_info_str(cur_ex) if user_frame_info_str: message += "\n{user_frame_info}".format( user_frame_info=indent(user_frame_info_str, " " * len(ex_id))) messages.append(message) if limit is None or limit: messages.extend( _nested_exceptions_messages(cur_ex, limit=limit, current="(%s)-> " % ex_id)) return messages
def tree_view(self, describe_format=None): """ Shows an ascii tree representation of the DAG """ # TODO: change to treelib implementation seen = set() def get_downstream(task, level=0): task_desc = self._describe_task(task, describe_format=describe_format) if task in seen: return [(level, "%s (*)" % task_desc)] result = [(level, task_desc)] seen.add(task) level += 1 count = 0 task_dag = task.ctrl.task_dag for t in task_dag.upstream: count += 1 if isinstance(t, DataSourceTask): continue if count > 30: result.append( (level, "..(%s tasks).." % len(task_dag.upstream))) break result.extend(get_downstream(t, level)) return result result = get_downstream(self.task) messages = [indent(msg, "\t" * level) for level, msg in result] logger.info( "Tasks Graph - (*) represent existing node in the graph run " "(green is completed, yellow is going to be submitted):\n%s", "\n".join(messages), )
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