diff --git a/keepalive-proxy.py b/keepalive-proxy.py index b6e54bb9..ae43b957 100755 --- a/keepalive-proxy.py +++ b/keepalive-proxy.py @@ -845,7 +845,9 @@ def engine_gone(): def why_unreachable(why): """What an engine that does not answer is said by, in words: an exception's, without Python's dressing, or what a caller of this wrote, a secret masked.""" - text = str(getattr(why, "reason", None) or why) + why = getattr(why, "reason", None) or why + # an error of a file names it: a path of the box is no client's + text = why.strerror if isinstance(why, OSError) and why.filename and why.strerror else str(why) text = re.sub(r"", r"\1", text) return mask_text(re.sub(r"\[Errno -?\d+\] ", "", text))[:400] diff --git a/tests/test_proxy_engine_gone.py b/tests/test_proxy_engine_gone.py index 02e8c911..f65ea8a5 100644 --- a/tests/test_proxy_engine_gone.py +++ b/tests/test_proxy_engine_gone.py @@ -54,6 +54,7 @@ def load(upstream): spec.loader.exec_module(mod) mod.journal = [] mod.log = mod.journal.append + mod._api_key = lambda: KEY # never the key of the box that runs the suite, nor its absence for name in ("image_lane_serving", "video_lane_serving", "transcribe_lane_serving"): setattr(mod, name, lambda: None) return mod @@ -160,6 +161,21 @@ class NoLane(Base): self.assertTrue([ln for ln in mod.journal if ln == "engine unreachable: Connection refused"], mod.journal) + def test_a_path_of_the_box_stays_here(self): + mod = self.serve(self.nobody) + mod.HOLD_UNITS, mod.HOLD_MAX_S = UNITS, 0 + mod.subprocess = SimpleNamespace(run=systemd(("inactive", "inactive"))) + + def missing(): + raise FileNotFoundError(2, "No such file or directory", "/home/someone/.config/qwen38/api-key") + mod._api_key = missing + status, _, raw = self.ask("/v1/systemone", b'{"state": "s", "model": "jev-latest", "questions": ' + b'{"a": {"type": "noul", "instructions": "x?"}}}') + self.assertEqual(status, 503, raw) + self.assertNotIn(b"/home/someone", raw) + self.assertIn(b"No such file or directory", raw) + + class WhatTheEngineSaid(Base): def said(self, body, ctype="application/json", path="/v1/chat/completions"): Engine.says = (503, body, ctype)