profiling: pass bytes to `_()` and `error.Abort()`
authorMatt Harbison <matt_harbison@yahoo.com>
Thu, 26 Sep 2024 02:58:50 +0200
changeset 51897 499b19683c1b
parent 51896 8583d138f436
child 51898 159854151f0f
profiling: pass bytes to `_()` and `error.Abort()` And of course `other_tool_name` is str too, so that needs to be converted. The type hints from PyCharm say `sys.monitoring.get_tool()` can return None, so handle that case explicitly before it trips up pytype.
mercurial/profiling.py
--- a/mercurial/profiling.py	Mon Jul 08 22:46:04 2024 +0200
+++ b/mercurial/profiling.py	Thu Sep 26 02:58:50 2024 +0200
@@ -71,11 +71,14 @@
         # what is going on.
         other_tool_name = sys.monitoring.get_tool(sys.monitoring.PROFILER_ID)
         if other_tool_name == "cProfile":
-            msg = 'cannot recursively call `lsprof`'
+            msg = b'cannot recursively call `lsprof`'
             raise error.Abort(msg) from None
         else:
-            m = 'failed to start "lsprofile"; another profiler already running: %s'
-            raise error.Abort(_(m) % other_tool_name) from None
+            tool = b'<unknown>'
+            if other_tool_name:
+                tool = encoding.strtolocal(other_tool_name)
+            m = b'failed to start "lsprofile"; another profiler already running: %s'
+            raise error.Abort(_(m) % tool) from None
     try:
         yield
     finally: