D7187: py3: fix fsmonitor error message formatting under Python3

touilleMan (Leblond Emmanuel) phabricator at mercurial-scm.org
Fri Nov 1 12:16:36 EDT 2019


touilleMan updated this revision to Diff 17435.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7187?vs=17434&id=17435

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7187/new/

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

AFFECTED FILES
  hgext/fsmonitor/__init__.py
  hgext/fsmonitor/watchmanclient.py

CHANGE DETAILS

diff --git a/hgext/fsmonitor/watchmanclient.py b/hgext/fsmonitor/watchmanclient.py
--- a/hgext/fsmonitor/watchmanclient.py
+++ b/hgext/fsmonitor/watchmanclient.py
@@ -10,6 +10,7 @@
 import getpass
 
 from mercurial import util
+from mercurial.utils.stringutil import forcebytestr
 
 from . import pywatchman
 
@@ -22,7 +23,7 @@
             self.warn = False
         self.invalidate = invalidate
 
-    def __str__(self):
+    def __bytes__(self):
         if self.warn:
             return b'warning: Watchman unavailable: %s' % self.msg
         else:
@@ -100,7 +101,7 @@
                 raise WatchmanNoRoot(self._root, ex.msg)
             raise Unavailable(ex.msg)
         except pywatchman.WatchmanError as ex:
-            raise Unavailable(str(ex))
+            raise Unavailable(forcebytestr(ex))
 
     def command(self, *args):
         try:
diff --git a/hgext/fsmonitor/__init__.py b/hgext/fsmonitor/__init__.py
--- a/hgext/fsmonitor/__init__.py
+++ b/hgext/fsmonitor/__init__.py
@@ -132,6 +132,7 @@
     util,
 )
 from mercurial import match as matchmod
+from mercurial.utils.stringutil import forcebytestr
 
 from . import (
     pywatchman,
@@ -192,7 +193,7 @@
             v[b"version"],
         )
     except watchmanclient.Unavailable as e:
-        err = str(e)
+        err = forcebytestr(e)
     fm.condwrite(
         err,
         b"fsmonitor-watchman-error",



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


More information about the Mercurial-devel mailing list