Patchwork D7214: fsmonitor: normalize exception types to bytes

login
register
mail settings
Submitter phabricator
Date Nov. 4, 2019, 4:28 p.m.
Message ID <24c36616d50dfdfdc790995135e43d72@localhost.localdomain>
Download mbox | patch
Permalink /patch/42724/
State Not Applicable
Headers show

Comments

phabricator - Nov. 4, 2019, 4:28 p.m.
Closed by commit rHG9a8f8c6ed965: fsmonitor: normalize exception types to bytes (authored by indygreg).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7214?vs=17512&id=17531

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

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

AFFECTED FILES
  hgext/fsmonitor/watchmanclient.py

CHANGE DETAILS




To: indygreg, #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
@@ -9,8 +9,14 @@ 
 
 import getpass
 
-from mercurial import util
-from mercurial.utils import procutil
+from mercurial import (
+    encoding,
+    util,
+)
+from mercurial.utils import (
+    procutil,
+    stringutil,
+)
 
 from . import pywatchman
 
@@ -23,12 +29,14 @@ 
             self.warn = False
         self.invalidate = invalidate
 
-    def __str__(self):
+    def __bytes__(self):
         if self.warn:
             return b'warning: Watchman unavailable: %s' % self.msg
         else:
             return b'Watchman unavailable: %s' % self.msg
 
+    __str__ = encoding.strmethod(__bytes__)
+
 
 class WatchmanNoRoot(Unavailable):
     def __init__(self, root, msg):
@@ -98,10 +106,12 @@ 
             return self._watchmanclient.query(*watchmanargs)
         except pywatchman.CommandError as ex:
             if b'unable to resolve root' in ex.msg:
-                raise WatchmanNoRoot(self._root, ex.msg)
+                raise WatchmanNoRoot(
+                    self._root, stringutil.forcebytestr(ex.msg)
+                )
             raise Unavailable(ex.msg)
         except pywatchman.WatchmanError as ex:
-            raise Unavailable(str(ex))
+            raise Unavailable(stringutil.forcebytestr(ex))
 
     def command(self, *args):
         try: