Patchwork [8,of,9] py3: don't use traceback.print_exc() in commandserver.py

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 18, 2018, 12:32 p.m.
Message ID <570e96ab987597acf146.1539865979@mimosa>
Download mbox | patch
Permalink /patch/36140/
State Accepted
Headers show

Comments

Yuya Nishihara - Oct. 18, 2018, 12:32 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1539672118 -7200
#      Tue Oct 16 08:41:58 2018 +0200
# Node ID 570e96ab987597acf146a6636f11f70494413745
# Parent  fe19b709e1219b716bcf8adcb2dbe053deb31d93
py3: don't use traceback.print_exc() in commandserver.py

It doesn't support a bytes stream on Python 3. This makes a traceback being
sent by one frame, but that shouldn't matter.

Patch

diff --git a/mercurial/commandserver.py b/mercurial/commandserver.py
--- a/mercurial/commandserver.py
+++ b/mercurial/commandserver.py
@@ -369,7 +369,7 @@  def _serverequest(ui, repo, conn, create
             cerr = sv.cerr
         else:
             cerr = channeledoutput(fout, 'e')
-        traceback.print_exc(file=cerr)
+        cerr.write(encoding.strtolocal(traceback.format_exc()))
         raise
     finally:
         fin.close()
diff --git a/tests/test-commandserver.t b/tests/test-commandserver.t
--- a/tests/test-commandserver.t
+++ b/tests/test-commandserver.t
@@ -786,8 +786,9 @@  unix domain socket:
   ...     while True:
   ...         try:
   ...             ch, data = readchannel(conn)
-  ...             if not data.startswith(b'  '):
-  ...                 bprint(b'%c, %r' % (ch, data))
+  ...             for l in data.splitlines(True):
+  ...                 if not l.startswith(b'  '):
+  ...                     bprint(b'%c, %r' % (ch, l))
   ...         except EOFError:
   ...             break
   >>> check(earlycrash, server.connect)