Patchwork D7187: py3: fix fsmonitor error message formatting under Python3

login
register
mail settings
Submitter phabricator
Date Nov. 1, 2019, 4:16 p.m.
Message ID <34253c50740813d60732e3d6b440f89e@localhost.localdomain>
Download mbox | patch
Permalink /patch/42646/
State Not Applicable
Headers show

Comments

phabricator - Nov. 1, 2019, 4:16 p.m.
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




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

Patch

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",