Patchwork D2209: ui: convert stack traces to sysbytes before logging

login
register
mail settings
Submitter phabricator
Date Feb. 13, 2018, 3:30 a.m.
Message ID <differential-rev-PHID-DREV-6hfnhuslhjmzyy33esaz-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27782/
State Superseded
Headers show

Comments

phabricator - Feb. 13, 2018, 3:30 a.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  They're coming back as unicodes, so sysbytes seems like the best we can do.
  
  This is like https://phab.mercurial-scm.org/D2171 and https://phab.mercurial-scm.org/D2172, but those fail on Python 2.7.5
  (seriously!), so this is my version of the same change. I actually
  wrote this before reviewing those, then discarded it, then came back
  to it after finding out 2.7.5 is a silly place.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2209

AFFECTED FILES
  mercurial/ui.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1620,10 +1620,12 @@ 
         else:
             curframe = inspect.currentframe()
             calframe = inspect.getouterframes(curframe, 2)
-            self.write_err('%s at: %s:%s (%s)\n'
-                           % ((msg,) + calframe[stacklevel][1:4]))
-            self.log('develwarn', '%s at: %s:%s (%s)\n',
-                     msg, *calframe[stacklevel][1:4])
+            fname, lineno, fmsg = calframe[stacklevel][1:4]
+            fname, fmsg = pycompat.sysbytes(fname), pycompat.sysbytes(fmsg)
+            self.write_err('%s at: %s:%d (%s)\n'
+                           % (msg, fname, lineno, fmsg))
+            self.log('develwarn', '%s at: %s:%d (%s)\n',
+                     msg, fname, lineno, fmsg)
             curframe = calframe = None  # avoid cycles
 
     def deprecwarn(self, msg, version, stacklevel=2):