diff options
author | Zhi Yan Liu <zhiyanl@cn.ibm.com> | 2014-09-18 13:37:58 +0800 |
---|---|---|
committer | Zhi Yan Liu <lzy.dev@gmail.com> | 2014-09-19 11:19:34 +0000 |
commit | 03331b19f327234d7f8f060d0cd361b2e36330c1 (patch) | |
tree | e4d88e8a343598023846d2f65d6d1579ab9ff4ea /glance_store/common | |
parent | 7628f2bc56fa530b6d577d57c46a27916992b6b3 (diff) | |
download | glance_store-03331b19f327234d7f8f060d0cd361b2e36330c1.tar.gz |
Adding common.utils.exception_to_str() to avoid encoding issue
1. Ported common.utils.exception_to_str() back to glance_store.
2. Used exception_to_str() to consistently cast the exception to avoid
potential encoding issue.
Change-Id: I398ea0e218ebb37b9041cfe82f18b11e614662bf
Related-Id: I77478a8eeeefd85bf98138156429df53d0a4c079
Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
Diffstat (limited to 'glance_store/common')
-rw-r--r-- | glance_store/common/config.py | 3 | ||||
-rw-r--r-- | glance_store/common/utils.py | 15 |
2 files changed, 17 insertions, 1 deletions
diff --git a/glance_store/common/config.py b/glance_store/common/config.py index 17e5b42..7ec3824 100644 --- a/glance_store/common/config.py +++ b/glance_store/common/config.py @@ -26,6 +26,7 @@ from oslo.config import cfg from paste import deploy from glance.version import version_info as version +from glance_store.common import utils paste_deploy_opts = [ cfg.StrOpt('flavor', @@ -213,6 +214,6 @@ def load_paste_app(app_name, flavor=None, conf_file=None): "configuration file %(conf_file)s." "\nGot: %(e)r") % {'app_name': app_name, 'conf_file': conf_file, - 'e': e}) + 'e': utils.exception_to_str(e)}) logger.error(msg) raise RuntimeError(msg) diff --git a/glance_store/common/utils.py b/glance_store/common/utils.py index fb77519..d240b86 100644 --- a/glance_store/common/utils.py +++ b/glance_store/common/utils.py @@ -25,6 +25,9 @@ try: from eventlet import sleep except ImportError: from time import sleep +import six + +from glance_store.openstack.common import strutils LOG = logging.getLogger(__name__) @@ -137,3 +140,15 @@ class CooperativeReader(object): def __iter__(self): return cooperative_iter(self.fd.__iter__()) + + +def exception_to_str(exc): + try: + error = six.text_type(exc) + except UnicodeError: + try: + error = str(exc) + except UnicodeError: + error = ("Caught '%(exception)s' exception." % + {"exception": exc.__class__.__name__}) + return strutils.safe_encode(error, errors='ignore') |