From: Kefu Chai Date: Tue, 3 Mar 2020 16:18:35 +0000 (+0800) Subject: mgr/orch: try harder when pickle fails to marshal an exception X-Git-Tag: v15.1.1~132^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=146fd472a157b6906b857b75dc437dae7f8ef428;p=ceph.git mgr/orch: try harder when pickle fails to marshal an exception 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 --- diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index de285f64c60e..d1e3478230fe 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -247,9 +247,14 @@ class _Promise(object): 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):