changeset 51741:d748fd2647f8

pure: stringify builtin exception messages Builtin exceptions usually want strings, and display with a wierd b'' prefix if given bytes.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 25 Jul 2024 14:40:38 -0400
parents 7226f2626fb1
children b619ba39d10a
files mercurial/pure/mpatch.py mercurial/pure/parsers.py
diffstat 2 files changed, 9 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/pure/mpatch.py	Mon Jul 29 12:10:08 2024 -0400
+++ b/mercurial/pure/mpatch.py	Thu Jul 25 14:40:38 2024 -0400
@@ -106,7 +106,7 @@
             try:
                 p1, p2, l = struct.unpack(b">lll", m.read(12))
             except struct.error:
-                raise mpatchError(b"patch cannot be decoded")
+                raise mpatchError("patch cannot be decoded")
             _pull(new, frags, p1 - last)  # what didn't change
             _pull([], frags, p2 - p1)  # what got deleted
             new.append((l, pos + 12))  # what got added
@@ -137,7 +137,7 @@
         outlen += length
 
     if bin != binend:
-        raise mpatchError(b"patch cannot be decoded")
+        raise mpatchError("patch cannot be decoded")
 
     outlen += orig - last
     return outlen
--- a/mercurial/pure/parsers.py	Mon Jul 29 12:10:08 2024 -0400
+++ b/mercurial/pure/parsers.py	Thu Jul 25 14:40:38 2024 -0400
@@ -25,6 +25,7 @@
 
 from .. import (
     error,
+    pycompat,
     revlogutils,
     util,
 )
@@ -235,7 +236,7 @@
                     parentfiledata=(mode, size, (mtime, 0, False)),
                 )
         else:
-            raise RuntimeError(b'unknown state: %s' % state)
+            raise RuntimeError('unknown state: %s' % pycompat.sysstr(state))
 
     def set_possibly_dirty(self):
         """Mark a file as "possibly dirty"
@@ -651,7 +652,7 @@
 
     def _check_index(self, i):
         if not isinstance(i, int):
-            raise TypeError(b"expecting int indexes")
+            raise TypeError("expecting int indexes")
         if i < 0 or i >= len(self):
             raise IndexError(i)
 
@@ -711,7 +712,7 @@
 
     def __delitem__(self, i):
         if not isinstance(i, slice) or not i.stop == -1 or i.step is not None:
-            raise ValueError(b"deleting slices only supports a:-1 with step 1")
+            raise ValueError("deleting slices only supports a:-1 with step 1")
         i = i.start
         self._check_index(i)
         self._stripnodes(i)
@@ -790,12 +791,12 @@
             count += 1
             off += self.entry_size + s
         if off != len(self._data):
-            raise ValueError(b"corrupted data")
+            raise ValueError("corrupted data")
         return count
 
     def __delitem__(self, i):
         if not isinstance(i, slice) or not i.stop == -1 or i.step is not None:
-            raise ValueError(b"deleting slices only supports a:-1 with step 1")
+            raise ValueError("deleting slices only supports a:-1 with step 1")
         i = i.start
         self._check_index(i)
         self._stripnodes(i)
@@ -848,7 +849,7 @@
             raise KeyError
         self._check_index(rev)
         if rev < self._lgt:
-            msg = b"cannot rewrite entries outside of this transaction"
+            msg = "cannot rewrite entries outside of this transaction"
             raise KeyError(msg)
         else:
             entry = list(self[rev])