From 7dcc583d63c554230f18d9d54a1dec2095144c03 Mon Sep 17 00:00:00 2001 From: Andrew Scorpil Date: Mon, 14 Dec 2015 21:52:42 +0100 Subject: [PATCH] Fix issue #982: UTF-8 encode error message before passing it to clint. --- AUTHORS | 1 + hy/cmdline.py | 18 +++++++++--------- hy/errors.py | 9 ++------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/AUTHORS b/AUTHORS index 26fdb81..ed43dc7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -66,3 +66,4 @@ * Matthew Egan Odendahl * Tim Martin * Johnathon Mlady +* Andrew Savchyn diff --git a/hy/cmdline.py b/hy/cmdline.py index ac08583..195a5bc 100644 --- a/hy/cmdline.py +++ b/hy/cmdline.py @@ -97,7 +97,7 @@ class HyREPL(code.InteractiveConsole): if e.source is None: e.source = source e.filename = filename - sys.stderr.write(str(e)) + print(e, file=sys.stderr) return False try: @@ -110,7 +110,7 @@ class HyREPL(code.InteractiveConsole): e.source = source e.filename = filename if SIMPLE_TRACEBACKS: - sys.stderr.write(str(e)) + print(e, file=sys.stderr) else: self.showtraceback() return False @@ -184,7 +184,7 @@ def pretty_error(func, *args, **kw): return func(*args, **kw) except (HyTypeError, LexException) as e: if SIMPLE_TRACEBACKS: - sys.stderr.write(str(e)) + print(e, file=sys.stderr) sys.exit(1) raise @@ -201,8 +201,8 @@ def run_module(mod_name): sys.argv = [pth] + sys.argv return run_file(pth) - sys.stderr.write("{0}: module '{1}' not found.\n".format(hy.__appname__, - mod_name)) + print("{0}: module '{1}' not found.\n".format(hy.__appname__, mod_name), + file=sys.stderr) return 1 @@ -328,8 +328,8 @@ def cmdline_handler(scriptname, argv): try: return run_file(options.args[0]) except HyIOError as e: - sys.stderr.write("hy: Can't open file '%s': [Errno %d] %s\n" % - (e.filename, e.errno, e.strerror)) + print("hy: Can't open file '{0}': [Errno {1}] {2}\n".format( + e.filename, e.errno, e.strerror), file=sys.stderr) sys.exit(e.errno) # User did NOTHING! @@ -356,8 +356,8 @@ def hyc_main(): print("Compiling %s" % file) pretty_error(write_hy_as_pyc, file) except IOError as x: - sys.stderr.write("hyc: Can't open file '%s': [Errno %d] %s\n" % - (x.filename, x.errno, x.strerror)) + print("hyc: Can't open file '{0}': [Errno {1}] {2}\n".format( + x.filename, x.errno, x.strerror), file=sys.stderr) sys.exit(x.errno) diff --git a/hy/errors.py b/hy/errors.py index 931656f..34ef31c 100644 --- a/hy/errors.py +++ b/hy/errors.py @@ -25,8 +25,6 @@ import traceback from clint.textui import colored -from hy._compat import PY3 - class HyError(Exception): """ @@ -101,12 +99,9 @@ class HyTypeError(TypeError): result += colored.yellow("%s: %s\n\n" % (self.__class__.__name__, - self.message)) + self.message.encode('utf-8'))) - if not PY3: - return result.encode('utf-8') - else: - return result + return result class HyMacroExpansionError(HyTypeError):