Open dnadlinger opened 1 year ago
Hacky patch when tracking down where this came from:
diff --git a/artiq/coredevice/comm_kernel.py b/artiq/coredevice/comm_kernel.py
index 3d5b8dea9..d37173bbc 100644
--- a/artiq/coredevice/comm_kernel.py
+++ b/artiq/coredevice/comm_kernel.py
@@ -14,6 +14,12 @@ from sipyco.keepalive import create_connection
logger = logging.getLogger(__name__)
+def format_core_exception(message, params):
+ for i, p in enumerate(params):
+ message = message.replace("{" + str(i) + "}", str(p))
+ return message
+
+
class Request(Enum):
SystemInfo = 3
@@ -687,8 +693,7 @@ class CommKernel:
python_exn_type = embedding_map.retrieve_object(core_exn.id)
try:
- python_exn = python_exn_type(
- nested_exceptions[-1][1].format(*nested_exceptions[0][2]))
+ python_exn = python_exn_type(format_core_exception(nested_exceptions[-1][1], nested_exceptions[0][2]))
except Exception as ex:
python_exn = RuntimeError(
f"Exception type={python_exn_type}, which couldn't be "
diff --git a/artiq/coredevice/exceptions.py b/artiq/coredevice/exceptions.py
index 7b6967743..ffaae1d36 100644
--- a/artiq/coredevice/exceptions.py
+++ b/artiq/coredevice/exceptions.py
@@ -14,6 +14,12 @@ RuntimeError = builtins.RuntimeError
AssertionError = builtins.AssertionError
+def format_core_exception(message, params):
+ for i, p in enumerate(params):
+ message = message.replace("{" + str(i) + "}", str(p))
+ return message
+
+
class CoreException:
"""Information about an exception raised or passed through the core device."""
def __init__(self, exceptions, exception_info, traceback, stack_pointers):
@@ -70,14 +76,13 @@ class CoreException:
self.stack_pointers[start_backtrace_index:]))
exception = self.exceptions[exception_index]
name = exception[0]
- message = exception[1]
- params = exception[2]
+ message = format_core_exception(exception[1], exception[2])
if ':' in name:
exn_id, name = name.split(':', 2)
exn_id = int(exn_id)
else:
exn_id = 0
- lines.append("{}({}): {}".format(name, exn_id, message.format(*params)))
+ lines.append("{}({}): {}".format(name, exn_id, message))
zipped.append(((exception[3], exception[4], exception[5], exception[6],
None, []), None))
The python_exn_type(nested_exceptions[-1][1].format(*nested_exceptions[0][2]))
looks potentially dodgy as well (mixing of -1 and 0 outer indices).
Can confirm this for release-7 branch
Bug Report
One-Line Summary
Exception messages containing substrings looking like format string messages (e.g.
{foo}
) lead to internal error when marshalled between host and core device.Issue Details
leads to
This isn't easy to work around, as the exception message might not come directly from user code (perhaps even another language where
{…}
isn't related to string interpolation, as was the case with Julia in the application here).This is probably a regression introduced during the recent exception message rework, though I haven't actually tested older versions.
Your System