changeset 51897:499b19683c1b

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.
author Matt Harbison <matt_harbison@yahoo.com>
date Thu, 26 Sep 2024 02:58:50 +0200
parents 8583d138f436
children 159854151f0f
files mercurial/profiling.py
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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: