summaryrefslogtreecommitdiff
path: root/taskflow/exceptions.py
diff options
context:
space:
mode:
authorIvan A. Melnikov <imelnikov@griddynamics.com>2014-02-04 15:07:16 +0400
committerJoshua Harlow <harlowja@yahoo-inc.com>2014-02-04 13:55:02 -0800
commitec908db1fc33fc113e8861ae3925064c5410caed (patch)
tree9bbf59258525feb845f7ee338e7d71ef450836df /taskflow/exceptions.py
parentde0398c45748e4012ec88ae80e342f4b9db00f82 (diff)
downloadtaskflow-ec908db1fc33fc113e8861ae3925064c5410caed.tar.gz
Be really careful with non-ascii data in exceptions/failures
When exception message is Python 2 str with non-ascii symbols, six.text_type(exc) raises UnicodeError. This change handles this case gracefully by calling str() instead of string.text_type() on such exceptions when retrieving messages for exceptions/failures. Closes-bug: 1276053 Change-Id: I2eb7318a7a5cd5dd687390a65abc0a45bd47de40
Diffstat (limited to 'taskflow/exceptions.py')
-rw-r--r--taskflow/exceptions.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/taskflow/exceptions.py b/taskflow/exceptions.py
index 698a446..1fa1767 100644
--- a/taskflow/exceptions.py
+++ b/taskflow/exceptions.py
@@ -16,6 +16,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import six
+
class TaskFlowException(Exception):
"""Base class for exceptions emitted from this library."""
@@ -136,4 +138,16 @@ class WrappedFailure(TaskFlowException):
return None
def __str__(self):
- return 'WrappedFailure: %s' % [str(cause) for cause in self._causes]
+ causes = [exception_message(cause) for cause in self._causes]
+ return 'WrappedFailure: %s' % causes
+
+
+def exception_message(exc):
+ """Return the string representation of exception."""
+ # NOTE(imelnikov): Dealing with non-ascii data in python is difficult:
+ # https://bugs.launchpad.net/taskflow/+bug/1275895
+ # https://bugs.launchpad.net/taskflow/+bug/1276053
+ try:
+ return six.text_type(exc)
+ except UnicodeError:
+ return str(exc)