~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/errors.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-24 00:08:33 UTC
  • mfrom: (1954 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1979.
  • Revision ID: john@arbash-meinel.com-20060824000833-f32d5cbef4fa4f78
[merge] bzr.dev 1954

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
 
127
127
    def __str__(self):
128
128
        try:
129
 
            return self.__doc__ % self.__dict__
 
129
            # __str__() should always return a 'str' object
 
130
            # never a 'unicode' object.
 
131
            s = self.__doc__ % self.__dict__
 
132
            if isinstance(s, unicode):
 
133
                return s.encode('utf8')
 
134
            return s
130
135
        except (NameError, ValueError, KeyError), e:
131
136
            return 'Unprintable exception %s: %s' \
132
137
                % (self.__class__.__name__, str(e))
197
202
    # BzrCommandError, and non-UI code should not throw a subclass of
198
203
    # BzrCommandError.  ADHB 20051211
199
204
    def __init__(self, msg):
200
 
        self.msg = msg
 
205
        # Object.__str__() must return a real string
 
206
        # returning a Unicode string is a python error.
 
207
        if isinstance(msg, unicode):
 
208
            self.msg = msg.encode('utf8')
 
209
        else:
 
210
            self.msg = msg
201
211
 
202
212
    def __str__(self):
203
213
        return self.msg