Remote exception names are cut to 128 identifier characters before a class is built for them

This commit is contained in:
2026-10-14 23:31:47 +02:00
parent df78cdac72
commit 30fa2b07db
2 changed files with 17 additions and 1 deletions
+4
View File
@@ -17,6 +17,7 @@ import itertools
import logging
import os
import queue
import re
import select
import signal
import subprocess
@@ -102,6 +103,8 @@ class NodeCancelled(RemoteError):
#: node code chose, so an unbounded cache is a node raising a class named after
#: its loop counter.
MAX_REMOTE_TYPES = 256
#: How long one of those names may be. A remote worker's comes off the wire.
MAX_REMOTE_NAME = 128
_remote_types: dict[str, type[RemoteError]] = {}
@@ -113,6 +116,7 @@ def _remote_class(name: str) -> type[RemoteError]:
the author still reads ``ValueError: bad input`` rather than the name of
the transport that carried it.
"""
name = re.sub(r"\W", "_", name[:MAX_REMOTE_NAME]) or "RemoteError"
cls = _remote_types.get(name)
if cls is not None:
return cls