D7187: py3: fix fsmonitor error message formatting under Python3
touilleMan (Leblond Emmanuel)
phabricator at mercurial-scm.org
Fri Nov 1 16:14:20 UTC 2019
touilleMan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
The watchmanclient.Unavailable exception got an invalid __str__
method resulting in a crash when watchman is not available.
This fix also solve tests/test-install.t.
REPOSITORY
rHG Mercurial
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,10 +10,10 @@
import getpass
from mercurial import util
+from mercurial.utils.stringutil import forcebytestr
from . import pywatchman
-
class Unavailable(Exception):
def __init__(self, msg, warn=True, invalidate=False):
self.msg = msg
@@ -22,7 +22,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 +100,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