Skip to content

Commit cf8e6dd

Browse files
committed
Handle non-mapping config when syncing point size
Guard against non-dict parsed configs when loading/saving the point-size key. load_point_size_from_config now logs and returns None if the config is not a mapping; save_point_size_to_config logs and replaces a non-mapping config with an empty dict before updating the point-size value. This prevents type errors when the config file's top-level YAML value isn't a mapping.
1 parent 72a3a31 commit cf8e6dd

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/napari_deeplabcut/core/config_sync.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ def load_point_size_from_config(config_path: str | Path | None) -> int | None:
163163
logger.debug("Could not read config file %r", config_path, exc_info=True)
164164
return None
165165

166+
if not isinstance(cfg, dict):
167+
logger.debug(
168+
"Config file %r did not contain a mapping; ignoring for point-size load.",
169+
config_path,
170+
)
171+
return None
172+
166173
if _POINT_SIZE_KEY in cfg:
167174
return _coerce_point_size(cfg.get(_POINT_SIZE_KEY))
168175
return None
@@ -189,6 +196,13 @@ def save_point_size_to_config(config_path: str | Path | None, size: int) -> bool
189196
logger.debug("Could not read config file %r", config_path, exc_info=True)
190197
return False
191198

199+
if not isinstance(cfg, dict):
200+
logger.debug(
201+
"Config file %r did not contain a mapping; replacing with empty config for point-size sync.",
202+
config_path,
203+
)
204+
cfg = {}
205+
192206
old_value = cfg.get(_POINT_SIZE_KEY, None)
193207

194208
try:

0 commit comments

Comments
 (0)