Patchwork D7855: fsmonitor: properly handle str ex.msg

login
register
mail settings
Submitter phabricator
Date Jan. 14, 2020, 4:13 a.m.
Message ID <differential-rev-PHID-DREV-ty6ati6umgdwwvevyalp-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44302/
State Superseded
Headers show

Comments

phabricator - Jan. 14, 2020, 4:13 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  ex.msg is always a str, since pywatchman uses str for exception messages.
  
  This commit removes a b'' from a string compare to avoid types
  mismatch and adds a coercion to bytes before stuffing the exception
  message on our local exception type, which uses bytes for the message
  elsewhere in this file.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

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
@@ -105,11 +105,11 @@ 
                 )
             return self._watchmanclient.query(*watchmanargs)
         except pywatchman.CommandError as ex:
-            if b'unable to resolve root' in ex.msg:
+            if 'unable to resolve root' in ex.msg:
                 raise WatchmanNoRoot(
                     self._root, stringutil.forcebytestr(ex.msg)
                 )
-            raise Unavailable(ex.msg)
+            raise Unavailable(stringutil.forcebytestr(ex.msg))
         except pywatchman.WatchmanError as ex:
             raise Unavailable(stringutil.forcebytestr(ex))