Skip to content

Commit 98da674

Browse files
committed
When loading plugin configs, catch KeyError on unavailable plugins and list all available.
Signed-off-by: Pedro Algarvio <[email protected]>
1 parent 05b2553 commit 98da674

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

changelog/68.improvement.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Several improvements to the project
2+
3+
* When loading plugin configs, catch `KeyError` on unavailable plugins and list all available.

src/saf/models.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,15 @@ def loaded_plugin(self: CCB) -> ModuleType:
109109
"""
110110
Return the plugin instance(module) for which this configuration refers to.
111111
"""
112-
return PluginsList.instance().collectors[self.plugin]
112+
try:
113+
return PluginsList.instance().collectors[self.plugin]
114+
except KeyError as exc:
115+
log.warning(
116+
"Failed to load %r collector plugin. Available collector plugins: %s",
117+
self.plugin,
118+
list(PluginsList.instance().collectors),
119+
)
120+
raise exc from None
113121

114122

115123
PCB = TypeVar("PCB", bound="ProcessConfigBase")
@@ -125,7 +133,15 @@ def loaded_plugin(self: PCB) -> ModuleType:
125133
"""
126134
Return the plugin instance(module) for which this configuration refers to.
127135
"""
128-
return PluginsList.instance().processors[self.plugin]
136+
try:
137+
return PluginsList.instance().processors[self.plugin]
138+
except KeyError as exc:
139+
log.warning(
140+
"Failed to load %r processor plugin. Available processor plugins: %s",
141+
self.plugin,
142+
list(PluginsList.instance().processors),
143+
)
144+
raise exc from None
129145

130146

131147
FCB = TypeVar("FCB", bound="ForwardConfigBase")
@@ -141,7 +157,15 @@ def loaded_plugin(self: FCB) -> ModuleType:
141157
"""
142158
Return the plugin instance(module) for which this configuration refers to.
143159
"""
144-
return PluginsList.instance().forwarders[self.plugin]
160+
try:
161+
return PluginsList.instance().forwarders[self.plugin]
162+
except KeyError as exc:
163+
log.warning(
164+
"Failed to load %r forwarder plugin. Available forwarder plugins: %s",
165+
self.plugin,
166+
list(PluginsList.instance().forwarders),
167+
)
168+
raise exc from None
145169

146170

147171
PC = TypeVar("PC", bound="PipelineConfig")

0 commit comments

Comments
 (0)