Be more tolerant of unicode exceptions
When an exception message is in unicode we should not fail when trying to get that unicode containing exceptions message so instead of using str() use a new utils function that has been working in other projects to attempt to convert a exception message into its corresponding unicode in a safer manner. Change-Id: I202f12d8f9bf562972b760f91805dba2ad14d804changes/32/122032/2
parent
a07fe43b3d
commit
9d0836c710
|
@ -26,6 +26,7 @@ import six
|
|||
|
||||
from tooz import coordination
|
||||
from tooz import locking
|
||||
from tooz import utils
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -131,7 +132,7 @@ class MemcachedDriver(coordination.CoordinationDriver):
|
|||
timeout=self.timeout,
|
||||
connect_timeout=self.timeout)
|
||||
except Exception as e:
|
||||
raise coordination.ToozConnectionError(e)
|
||||
raise coordination.ToozConnectionError(utils.exception_message(e))
|
||||
self._group_members = collections.defaultdict(set)
|
||||
self._acquired_locks = []
|
||||
self.heartbeat()
|
||||
|
|
|
@ -24,6 +24,7 @@ import six
|
|||
|
||||
from tooz import coordination
|
||||
from tooz import locking
|
||||
from tooz import utils
|
||||
|
||||
|
||||
class ZooKeeperLock(locking.Lock):
|
||||
|
@ -87,7 +88,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
|||
except exceptions.NoNodeError:
|
||||
raise coordination.ToozError("tooz namespace has not been created")
|
||||
except exceptions.ZookeeperError as e:
|
||||
raise coordination.ToozError(str(e))
|
||||
raise coordination.ToozError(utils.exception_message(e))
|
||||
|
||||
def create_group(self, group_id):
|
||||
group_path = self._path_group(group_id)
|
||||
|
@ -104,7 +105,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
|||
except exceptions.NoNodeError:
|
||||
raise coordination.GroupNotCreated(group_id)
|
||||
except exceptions.ZookeeperError as e:
|
||||
raise coordination.ToozError(str(e))
|
||||
raise coordination.ToozError(utils.exception_message(e))
|
||||
|
||||
def join_group(self, group_id, capabilities=b""):
|
||||
member_path = self._path_member(group_id, self._member_id)
|
||||
|
@ -121,7 +122,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
|||
except exceptions.NoNodeError:
|
||||
raise coordination.MemberNotJoined(group_id, member_id)
|
||||
except exceptions.ZookeeperError as e:
|
||||
raise coordination.ToozError(str(e))
|
||||
raise coordination.ToozError(utils.exception_message(e))
|
||||
|
||||
def leave_group(self, group_id):
|
||||
member_path = self._path_member(group_id, self._member_id)
|
||||
|
@ -136,7 +137,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
|||
except exceptions.NoNodeError:
|
||||
raise coordination.GroupNotCreated(group_id)
|
||||
except exceptions.ZookeeperError as e:
|
||||
raise coordination.ToozError(str(e))
|
||||
raise coordination.ToozError(utils.exception_message(e))
|
||||
else:
|
||||
return set(m.encode('ascii') for m in members_ids)
|
||||
|
||||
|
@ -154,7 +155,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
|||
except exceptions.NoNodeError:
|
||||
raise coordination.MemberNotJoined(group_id, member_id)
|
||||
except exceptions.ZookeeperError as e:
|
||||
raise coordination.ToozError(str(e))
|
||||
raise coordination.ToozError(utils.exception_message(e))
|
||||
|
||||
def update_capabilities(self, group_id, capabilities):
|
||||
member_path = self._path_member(group_id, self._member_id)
|
||||
|
@ -170,7 +171,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
|||
except exceptions.NoNodeError:
|
||||
raise coordination.MemberNotJoined(group_id, member_id)
|
||||
except exceptions.ZookeeperError as e:
|
||||
raise coordination.ToozError(str(e))
|
||||
raise coordination.ToozError(utils.exception_message(e))
|
||||
else:
|
||||
return capabilities
|
||||
|
||||
|
@ -188,7 +189,7 @@ class BaseZooKeeperDriver(coordination.CoordinationDriver):
|
|||
except exceptions.NoNodeError:
|
||||
raise coordination.ToozError("tooz namespace has not been created")
|
||||
except exceptions.ZookeeperError as e:
|
||||
raise coordination.ToozError(str(e))
|
||||
raise coordination.ToozError(utils.exception_message(e))
|
||||
else:
|
||||
return set(g.encode('ascii') for g in group_ids)
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (C) 2014 Yahoo! Inc. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
|
||||
def exception_message(exc):
|
||||
"""Return the string representation of exception."""
|
||||
try:
|
||||
return six.text_type(exc)
|
||||
except UnicodeError:
|
||||
return str(exc)
|
Loading…
Reference in New Issue