Skip to content

Commit

Permalink
Fixed unicode behavior for exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Dec 6, 2017
1 parent ebcbef9 commit 9bd66b3
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -14,6 +14,9 @@ Version 6.8
- Fix crash on Windows console, see #744.
- Fix bashcompletion on chained commands. See #754.
- Fix option naming routine to match documentation. See #793
- Fixed the behavior of click error messages with regards to unicode on 2.x
and 3.x respectively. Message is now always unicode and the str and unicode
special methods work as you expect on that platform.

Version 6.7
-----------
12 changes: 9 additions & 3 deletions click/exceptions.py
Original file line number Diff line number Diff line change
@@ -9,15 +9,21 @@ class ClickException(Exception):
exit_code = 1

def __init__(self, message):
if PY2:
if message is not None:
message = message.encode('utf-8')
Exception.__init__(self, message)
self.message = message

def format_message(self):
return self.message

def __str__(self):
return self.message

if PY2:
__unicode__ = __str__

def __str__(self):
return self.message.encode('utf-8')

def show(self, file=None):
if file is None:
file = get_text_stderr()

0 comments on commit 9bd66b3

Please sign in to comment.