summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2022-04-03 08:12:10 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-03 08:39:36 +0000
commitbd0be154aa5f1d04136efc8cb0bd2d40fac3f0ab (patch)
treef3277e9825f8f2c1c25ccf0da99345a760d0e141
parentaaae37f453b94ecd6cfd4bf4261a36a42389885c (diff)
downloadmongo-bd0be154aa5f1d04136efc8cb0bd2d40fac3f0ab.tar.gz
SERVER-65125 Fix Status/StatusWith printing in mongo_printers.py
-rw-r--r--buildscripts/gdb/mongo_printers.py43
1 files changed, 24 insertions, 19 deletions
diff --git a/buildscripts/gdb/mongo_printers.py b/buildscripts/gdb/mongo_printers.py
index 07ebc47bd64..b6b7f8099ee 100644
--- a/buildscripts/gdb/mongo_printers.py
+++ b/buildscripts/gdb/mongo_printers.py
@@ -37,22 +37,34 @@ def get_unique_ptr(obj):
class StatusPrinter(object):
"""Pretty-printer for mongo::Status."""
+ @staticmethod
+ def extract_error(val):
+ """Extract the error object (if any) from a Status/StatusWith."""
+ error = val['_error']
+ if 'px' in error.type.iterkeys():
+ return error['px']
+ return error
+
+ @staticmethod
+ def generate_error_details(error):
+ """Generate a (code,reason) tuple from a Status/StatusWith error object."""
+ info = error.dereference()
+ code = info['code']
+ # Remove the mongo::ErrorCodes:: prefix. Does nothing if not a real ErrorCode.
+ code = str(code).split('::')[-1]
+
+ return (code, info['reason'])
+
def __init__(self, val):
"""Initialize StatusPrinter."""
self.val = val
def to_string(self):
"""Return status for printing."""
- if not self.val['_error']:
+ error = StatusPrinter.extract_error(self.val)
+ if not error:
return 'Status::OK()'
-
- code = self.val['_error']['code']
- # Remove the mongo::ErrorCodes:: prefix. Does nothing if not a real ErrorCode.
- code = str(code).split('::')[-1]
-
- info = self.val['_error'].dereference()
- reason = info['reason']
- return 'Status(%s, %s)' % (code, reason)
+ return 'Status(%s, %s)' % StatusPrinter.generate_error_details(error)
class StatusWithPrinter(object):
@@ -64,17 +76,10 @@ class StatusWithPrinter(object):
def to_string(self):
"""Return status for printing."""
- if not self.val['_status']['_error']:
+ error = StatusPrinter.extract_error(self.val['_status'])
+ if not error:
return 'StatusWith(OK, %s)' % (self.val['_t'])
-
- code = self.val['_status']['_error']['code']
-
- # Remove the mongo::ErrorCodes:: prefix. Does nothing if not a real ErrorCode.
- code = str(code).split('::')[-1]
-
- info = self.val['_status']['_error'].dereference()
- reason = info['reason']
- return 'StatusWith(%s, %s)' % (code, reason)
+ return 'StatusWith(%s, %s)' % StatusPrinter.generate_error_details(error)
class StringDataPrinter(object):