From: Kefu Chai Date: Tue, 3 Jan 2017 12:40:00 +0000 (+0800) Subject: ceph-disk: convert none str to str before printing it X-Git-Tag: v10.2.6~82^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=18545a27eccfa0b22b1782bb52e3f47afef8ec39;p=ceph.git ceph-disk: convert none str to str before printing it Error('somethings goes wrong', e) is thrown if exception `e` is caught in ceph-disk, where e is not a string. so we can not just concat it in Error's __str__(). so cast it to str before doing so. introduced by d0e29c7 Fixes: http://tracker.ceph.com/issues/18371 Signed-off-by: Kefu Chai (cherry picked from commit 5e0dd1e7df43a3be589d17878714756a22052d8e) --- diff --git a/src/ceph-disk/ceph_disk/main.py b/src/ceph-disk/ceph_disk/main.py index ffe0311ceb79..2a929d725478 100755 --- a/src/ceph-disk/ceph_disk/main.py +++ b/src/ceph-disk/ceph_disk/main.py @@ -268,7 +268,12 @@ class Error(Exception): def __str__(self): doc = _bytes2str(self.__doc__.strip()) - return ': '.join([doc] + [_bytes2str(a) for a in self.args]) + try: + str_type = basestring + except NameError: + str_type = str + args = [a if isinstance(a, str_type) else str(a) for a in self.args] + return ': '.join([doc] + [_bytes2str(a) for a in args]) class MountError(Error):