tenseleyflow/sway / af06883

Browse files

core/errors: DlmCompatError — typed exception for dlm API drift (F06)

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
af068838075489e408edec3c9ca538b4344cf2df
Parents
c0c175e
Tree
8941ef9

1 changed file

StatusFile+-
M src/dlm_sway/core/errors.py 28 0
src/dlm_sway/core/errors.pymodified
@@ -63,3 +63,31 @@ class ProbeError(SwayError):
6363
     def __init__(self, probe: str, message: str) -> None:
6464
         super().__init__(f"probe {probe!r}: {message}")
6565
         self.probe = probe
66
+
67
+
68
+class DlmCompatError(SwayError):
69
+    """The installed ``dlm`` package's public surface doesn't match what
70
+    sway's resolver expects.
71
+
72
+    Raised when e.g. ``dlm.base_models.resolve`` returns an object
73
+    without the ``hf_id`` attribute we depend on — historically dlm
74
+    used ``hf_id``; if it renames to ``repo_id`` we want a loud,
75
+    actionable error with both version strings in the message, not a
76
+    silent pass-through that hands the backend a registry key it can't
77
+    load.
78
+
79
+    The installed-dlm version is introspected best-effort; it's
80
+    informational, not a key for programmatic branching.
81
+    """
82
+
83
+    def __init__(self, message: str, *, installed_dlm_version: str | None = None) -> None:
84
+        full = message
85
+        if installed_dlm_version:
86
+            full = f"{message} (installed dlm version: {installed_dlm_version})"
87
+        full = (
88
+            f"{full}\n"
89
+            "Hint: pin a compatible dlm with: pip install 'dlm-sway[dlm]' "
90
+            "(resolves the tested dlm version range from pyproject.toml)."
91
+        )
92
+        super().__init__(full)
93
+        self.installed_dlm_version = installed_dlm_version