pickle cannot marshal instances of class not defined in the top level of
a module. for instance, `DriveGroupValidationError` is defined in a
submodule of `ceph` python module, that's why we cannot capture it.
this prevent the `ceph` command line from getting a proper error when
the command fails if the command is implemented using cross python
module call(s).
Signed-off-by: Kefu Chai <kchai@redhat.com>
self._exception_ = e
try:
self._serialized_exception_ = pickle.dumps(e) if e is not None else None
- except Exception:
- logger.exception("failed to pickle {}".format(e))
- # We can't properly raise anything here. Just hope for the best.
+ except pickle.PicklingError:
+ logger.error(f"failed to pickle {e}")
+ if isinstance(e, Exception):
+ e = Exception(*e.args)
+ else:
+ e = Exception(str(e))
+ # degenerate to a plain Exception
+ self._serialized_exception_ = pickle.dumps(e)
@property
def _serialized_exception(self):