Skip to content

Commit

Permalink
BF(PY2): CommandError - make __str__ return bytes via assure_bytes, _…
Browse files Browse the repository at this point in the history
…_unicode__ to return str

Should be reverted in master where there is no PY2 compatibility
  • Loading branch information
yarikoptic committed Oct 18, 2019
1 parent 19ee052 commit 6bce96d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions datalad/support/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import re
from os import linesep

from six import PY2

class CommandError(RuntimeError):
"""Thrown if a command call fails.
Expand All @@ -25,16 +26,24 @@ def __init__(self, cmd="", msg="", code=None, stdout="", stderr=""):
self.stdout = stdout
self.stderr = stderr

def __str__(self):
from datalad.utils import assure_unicode
def _str(self):
from ..utils import assure_unicode
to_str = "%s: " % self.__class__.__name__
if self.cmd:
to_str += "command '%s'" % (self.cmd,)
if self.code:
to_str += " failed with exitcode %d" % self.code
to_str += "\n%s" % assure_unicode(self.msg)
to_str += "\n" + assure_unicode(self.msg)
return to_str

if PY2:
def __str__(self):
from ..utils import assure_bytes
return assure_bytes(self._str())
__unicode__ = _str
else:
__str__ = _str

This comment has been minimized.

Copy link
@kyleam

kyleam Oct 18, 2019

Contributor

FWIW this seems to deal with the same thing that @six.python_2_unicode_compatible would handle. (Ideally any of our classes that define __str__ would use that so that it'd work properly on py2.)

This comment has been minimized.

Copy link
@yarikoptic

yarikoptic Oct 18, 2019

Author Member

ah cool -- thanks, I should have checked. I will redo the fix now using it here. indeed, if to keep 0.11.x going forward much longer we should better review/do it for all others



class MissingExternalDependency(RuntimeError):
"""External dependency is missing error"""
Expand Down

0 comments on commit 6bce96d

Please sign in to comment.