当前位置: 首页>>代码示例>>Python>>正文


Python traceback.format_tb方法代码示例

本文整理汇总了Python中traceback.format_tb方法的典型用法代码示例。如果您正苦于以下问题:Python traceback.format_tb方法的具体用法?Python traceback.format_tb怎么用?Python traceback.format_tb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在traceback的用法示例。


在下文中一共展示了traceback.format_tb方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: format_exc

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def format_exc(exc: Exception, limit: int = -1, msg: Optional[str] = None):
    """
    Format `Exceptions` for use with `Stoq` error handling

    """
    # Inspired from https://github.com/python/cpython/blob/3.7/Lib/traceback.py#L560-L563
    tb = traceback.format_tb(exc.__traceback__, limit=limit)[0].split('\n')[0].strip()
    stype = type(exc).__qualname__
    smod = type(exc).__module__
    if smod not in ('__main__', 'builtins'):
        stype = f'{smod}.{stype}'
    exc_str = f'{tb} ; {stype}: {str(exc)}'
    if msg:
        return f'{msg}: {exc_str}'
    else:
        return exc_str 
开发者ID:PUNCH-Cyber,项目名称:stoq,代码行数:18,代码来源:__init__.py

示例2: _report_unexpected_error

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def _report_unexpected_error(self):

        error_type, error, tb = sys.exc_info()
        origin = tb

        while origin.tb_next is not None:
            origin = origin.tb_next

        filename = origin.tb_frame.f_code.co_filename
        lineno = origin.tb_lineno
        message = '{0} at "{1}", line {2:d} : {3}'.format(error_type.__name__, filename, lineno, error)

        environment.splunklib_logger.error(message + '\nTraceback:\n' + ''.join(traceback.format_tb(tb)))
        self.write_error(message)

    # endregion

    # region Types 
开发者ID:remg427,项目名称:misp42splunk,代码行数:20,代码来源:search_command.py

示例3: test_apps_list

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def test_apps_list(self):
        runner = CliRunner()
        result = runner.invoke(cli, ["get", "apps"])
        if result.exit_code:
            cli_res_dict = {"Output": result.output, "Exception": str(result.exception)}
            LOG.debug(
                "Cli Response: {}".format(
                    json.dumps(cli_res_dict, indent=4, separators=(",", ": "))
                )
            )
            LOG.debug(
                "Traceback: \n{}".format(
                    "".join(traceback.format_tb(result.exc_info[2]))
                )
            )
            pytest.fail("BP Get failed")
        LOG.info("Success") 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:19,代码来源:test_app_commands.py

示例4: test_apps_list_with_limit_offset

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def test_apps_list_with_limit_offset(self):
        runner = CliRunner()
        result = runner.invoke(cli, ["get", "apps", "--limit=15", "--offset=5"])
        if result.exit_code:
            cli_res_dict = {"Output": result.output, "Exception": str(result.exception)}
            LOG.debug(
                "Cli Response: {}".format(
                    json.dumps(cli_res_dict, indent=4, separators=(",", ": "))
                )
            )
            LOG.debug(
                "Traceback: \n{}".format(
                    "".join(traceback.format_tb(result.exc_info[2]))
                )
            )
        LOG.info("Success") 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:18,代码来源:test_app_commands.py

示例5: test_apps_list_with_name

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def test_apps_list_with_name(self):
        runner = CliRunner()
        result = runner.invoke(cli, ["get", "apps", "--name=MSSQL"])
        if result.exit_code:
            cli_res_dict = {"Output": result.output, "Exception": str(result.exception)}
            LOG.debug(
                "Cli Response: {}".format(
                    json.dumps(cli_res_dict, indent=4, separators=(",", ": "))
                )
            )
            LOG.debug(
                "Traceback: \n{}".format(
                    "".join(traceback.format_tb(result.exc_info[2]))
                )
            )
        LOG.info("Success") 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:18,代码来源:test_app_commands.py

示例6: _test_describe_app

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def _test_describe_app(self):
        runner = CliRunner()
        LOG.info("Running 'calm describe app' command")
        result = runner.invoke(cli, ["describe", "app", self.created_app_name])
        if result.exit_code:
            cli_res_dict = {"Output": result.output, "Exception": str(result.exception)}
            LOG.debug(
                "Cli Response: {}".format(
                    json.dumps(cli_res_dict, indent=4, separators=(",", ": "))
                )
            )
            LOG.debug(
                "Traceback: \n{}".format(
                    "".join(traceback.format_tb(result.exc_info[2]))
                )
            )
        LOG.info("Success") 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:19,代码来源:test_app_commands.py

示例7: _test_app_delete

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def _test_app_delete(self):
        runner = CliRunner()
        self._wait_for_non_busy_state()
        LOG.info("Deleting App {} ".format(self.created_app_name))
        result = runner.invoke(cli, ["delete", "app", self.created_app_name])
        if result.exit_code:
            cli_res_dict = {"Output": result.output, "Exception": str(result.exception)}
            LOG.debug(
                "Cli Response: {}".format(
                    json.dumps(cli_res_dict, indent=4, separators=(",", ": "))
                )
            )
            LOG.debug(
                "Traceback: \n{}".format(
                    "".join(traceback.format_tb(result.exc_info[2]))
                )
            )
        LOG.info("Success") 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:20,代码来源:test_app_commands.py

示例8: _test_dsl_bp_delete

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def _test_dsl_bp_delete(self):
        runner = CliRunner()
        LOG.info("Deleting Bp {} ".format(self.created_dsl_bp_name))
        result = runner.invoke(cli, ["delete", "bp", self.created_dsl_bp_name])
        if result.exit_code:
            cli_res_dict = {"Output": result.output, "Exception": str(result.exception)}
            LOG.debug(
                "Cli Response: {}".format(
                    json.dumps(cli_res_dict, indent=4, separators=(",", ": "))
                )
            )
            LOG.debug(
                "Traceback: \n{}".format(
                    "".join(traceback.format_tb(result.exc_info[2]))
                )
            )
        LOG.info("Success") 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:19,代码来源:test_app_commands.py

示例9: test_bps_list_with_limit_offset

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def test_bps_list_with_limit_offset(self):
        runner = CliRunner()
        result = runner.invoke(cli, ["get", "bps", "--limit=15", "--offset=5"])
        if result.exit_code:
            cli_res_dict = {"Output": result.output, "Exception": str(result.exception)}
            LOG.debug(
                "Cli Response: {}".format(
                    json.dumps(cli_res_dict, indent=4, separators=(",", ": "))
                )
            )
            LOG.debug(
                "Traceback: \n{}".format(
                    "".join(traceback.format_tb(result.exc_info[2]))
                )
            )
            pytest.fail("BP list with limit call failed")
        LOG.info("Success") 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:19,代码来源:test_bp_commands.py

示例10: test_bps_list_with_name

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def test_bps_list_with_name(self):
        runner = CliRunner()
        result = runner.invoke(cli, ["get", "bps", "--name=MSSQL"])
        if result.exit_code:
            cli_res_dict = {"Output": result.output, "Exception": str(result.exception)}
            LOG.debug(
                "Cli Response: {}".format(
                    json.dumps(cli_res_dict, indent=4, separators=(",", ": "))
                )
            )
            LOG.debug(
                "Traceback: \n{}".format(
                    "".join(traceback.format_tb(result.exc_info[2]))
                )
            )
            pytest.fail("BP list with name call failed")
        LOG.info("Success") 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:19,代码来源:test_bp_commands.py

示例11: test_compile_bp

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def test_compile_bp(self):
        runner = CliRunner()
        LOG.info("Compiling Bp file at {}".format(DSL_BP_FILEPATH))
        result = runner.invoke(
            cli, ["compile", "bp", "--file={}".format(DSL_BP_FILEPATH)]
        )

        if result.exit_code:
            cli_res_dict = {"Output": result.output, "Exception": str(result.exception)}
            LOG.debug(
                "Cli Response: {}".format(
                    json.dumps(cli_res_dict, indent=4, separators=(",", ": "))
                )
            )
            LOG.debug(
                "Traceback: \n{}".format(
                    "".join(traceback.format_tb(result.exc_info[2]))
                )
            )
            pytest.fail("BP compile command failed")
        LOG.info("Success") 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:23,代码来源:test_bp_commands.py

示例12: _test_dsl_bp_delete

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def _test_dsl_bp_delete(self):
        runner = CliRunner()
        LOG.info("Deleting DSL Bp {} ".format(self.created_dsl_bp_name))
        result = runner.invoke(cli, ["delete", "bp", self.created_dsl_bp_name])
        if result.exit_code:
            cli_res_dict = {"Output": result.output, "Exception": str(result.exception)}
            LOG.debug(
                "Cli Response: {}".format(
                    json.dumps(cli_res_dict, indent=4, separators=(",", ": "))
                )
            )
            LOG.debug(
                "Traceback: \n{}".format(
                    "".join(traceback.format_tb(result.exc_info[2]))
                )
            )
        LOG.info("Success") 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:19,代码来源:test_bp_commands.py

示例13: _test_json_bp_delete

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def _test_json_bp_delete(self):
        runner = CliRunner()
        LOG.info("Deleting JSON Bp {} ".format(self.created_json_bp_name))
        result = runner.invoke(cli, ["delete", "bp", self.created_json_bp_name])
        if result.exit_code:
            cli_res_dict = {"Output": result.output, "Exception": str(result.exception)}
            LOG.debug(
                "Cli Response: {}".format(
                    json.dumps(cli_res_dict, indent=4, separators=(",", ": "))
                )
            )
            LOG.debug(
                "Traceback: \n{}".format(
                    "".join(traceback.format_tb(result.exc_info[2]))
                )
            )
        LOG.info("Success") 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:19,代码来源:test_bp_commands.py

示例14: run

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def run(self, manual=False):
        """ execute the code in this file """ 
        r = Run(report=self.report, name=self.file_location, manual=manual)
        r.save()
        logger = RunLineLogger(r)
        try:
            report_object = report_map(self.file_location, logger)
            report_object.run()
            for artifact in report_object.artifacts:
                artifact.convert_to_unicode()
                try:
                    result = Result(run=r, name=artifact.title, table=artifact.to_dict() )
                except AttributeError:
                    result = Result(run=r, table=artifact.to_dict() ) 
                result.save()
            r.success = True
            r.save()
        except Exception as e:
            logger.log("ERROR: " + str(e) )
            type_, value_, traceback_ = sys.exc_info()
            logger.log( ",".join(traceback.format_tb( traceback_ )) )
        return r 
开发者ID:sfu-fas,项目名称:coursys,代码行数:24,代码来源:models.py

示例15: capture_exception

# 需要导入模块: import traceback [as 别名]
# 或者: from traceback import format_tb [as 别名]
def capture_exception(self, exc: Optional[BaseException] = None, user: Any = None,
                                context_env: Any = None,
                                severity: Optional[LogSeverity] = None):
        if exc:
            tb = exc.__traceback__
        else:
            _, exc, tb = sys.exc_info()
        exc_type: Any = type(exc)
        if severity is None:
            severity = LogSeverity.ERROR
        async with self.dbpool.acquire() as conn, conn.begin():
            query = error_logs.insert().values({
                'severity': severity,
                'source': 'manager',
                'user': user,
                'message': ''.join(traceback.format_exception_only(exc_type, exc)).strip(),
                'context_lang': 'python',
                'context_env': context_env,
                'traceback': ''.join(traceback.format_tb(tb)).strip()
            })
            await conn.execute(query)
        log.debug('Manager log collected: {}', str(exc)) 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:24,代码来源:error_monitor.py


注:本文中的traceback.format_tb方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。