當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。