Skip to content

Commit 9a36448

Browse files
committed
fix atomic writes for config manager
1 parent 171ce16 commit 9a36448

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tidy3d/config/manager.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,27 +301,35 @@ def _reload(self) -> None:
301301

302302
def _build_models(self) -> None:
303303
sections = get_sections()
304-
self._section_models.clear()
305-
self._plugin_models.clear()
304+
new_sections: dict[str, BaseModel] = {}
305+
new_plugins: dict[str, BaseModel] = {}
306306

307+
errors: list[tuple[str, Exception]] = []
307308
for name, schema in sections.items():
308309
if name.startswith("plugins."):
309310
plugin_name = name.split(".", 1)[1]
310311
plugin_data = _deep_get(self._effective_tree, ("plugins", plugin_name)) or {}
311312
try:
312-
self._plugin_models[plugin_name] = schema(**plugin_data)
313+
new_plugins[plugin_name] = schema(**plugin_data)
313314
except Exception as exc:
314315
log.error(f"Failed to load configuration for plugin '{plugin_name}': {exc}")
315-
raise
316+
errors.append((name, exc))
316317
continue
317318
if name == "plugins":
318319
continue
319320
section_data = self._effective_tree.get(name, {})
320321
try:
321-
self._section_models[name] = schema(**section_data)
322+
new_sections[name] = schema(**section_data)
322323
except Exception as exc:
323324
log.error(f"Failed to load configuration for section '{name}': {exc}")
324-
raise
325+
errors.append((name, exc))
326+
327+
if errors:
328+
# propagate the first error; others already logged
329+
raise errors[0][1]
330+
331+
self._section_models = new_sections
332+
self._plugin_models = new_plugins
325333

326334
def _get_model(self, name: str) -> Optional[BaseModel]:
327335
if name.startswith("plugins."):

0 commit comments

Comments
 (0)