✨ Support format string in get_exception_string helper
This commit is contained in:
1 parent
ecb99dbd9a
commit
d6a3f46892
1 file changed
+10
-9
@@ -449,7 +449,7 @@ def get_fully_qualified_classname(o):
|
||||
return module + "." + o.__class__.__name__
|
||||
|
||||
|
||||
def get_exception_string():
|
||||
def get_exception_string(fmt="{type}: '{message}' @ {file}:{function}:{line}"):
|
||||
"""
|
||||
Retrieves the exception info of the last raised exception and returns it as a string formatted as
|
||||
``<exception type>: <exception message> @ <source file>:<function name>:<line number>``.
|
||||
@@ -458,14 +458,15 @@ def get_exception_string():
|
||||
string: The formatted exception information.
|
||||
"""
|
||||
|
||||
locationInfo = traceback.extract_tb(sys.exc_info()[2])[0]
|
||||
return "%s: '%s' @ %s:%s:%d" % (
|
||||
str(sys.exc_info()[0].__name__),
|
||||
str(sys.exc_info()[1]),
|
||||
os.path.basename(locationInfo[0]),
|
||||
locationInfo[2],
|
||||
locationInfo[1],
|
||||
)
|
||||
location_info = traceback.extract_tb(sys.exc_info()[2])[0]
|
||||
exception = {
|
||||
"type": str(sys.exc_info()[0].__name__),
|
||||
"message": str(sys.exc_info()[1]),
|
||||
"file": os.path.basename(location_info[0]),
|
||||
"function": location_info[2],
|
||||
"line": location_info[1],
|
||||
}
|
||||
return fmt.format(**exception)
|
||||
|
||||
|
||||
@deprecated(
|
||||
|
||||
Reference in new issue
Block a user