Skip to content

Commit 4af3221

Browse files
Fix ConfigManagingActor crashing when any file was deleted
`event.path.samefile` raises error if: * `event.pathq` doesn't exists * path `p` doesn't exists In this case it raised exception: * if any file in parent directory was deleted * any path in self._config_paths didn't exist Signed-off-by: Elzbieta Kotulska <[email protected]>
1 parent 5f11e00 commit 4af3221

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/frequenz/sdk/config/_config_managing.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,16 @@ async def _run(self) -> None:
193193
# Since we are watching the whole parent directories, we need to make
194194
# sure we only react to events related to the configuration files we
195195
# are interested in.
196-
if not any(event.path.samefile(p) for p in self._config_paths):
196+
#
197+
# pathlib.Path.samefile raises error if any path doesn't exist so we need to
198+
# make sure `event.path` and `p` exists before calling it.
199+
#
200+
# On EventType.DELETE event the event.path won't exists and we have no way
201+
# to check if this path is in self._config_paths so we need to skip this
202+
# event.
203+
if not event.path.exists() or not any(
204+
event.path.samefile(p) for p in self._config_paths if p.exists()
205+
):
197206
continue
198207

199208
match event.type:
@@ -212,10 +221,10 @@ async def _run(self) -> None:
212221
)
213222
await self.send_config()
214223
case EventType.DELETE:
215-
_logger.info(
216-
"%s: The configuration file %s was deleted, ignoring...",
217-
self,
218-
event.path,
224+
# Deletion should be handled in the if statement above by checking
225+
# if event.path exists.
226+
raise RuntimeError(
227+
"DELETE event should be handled in the if statement above"
219228
)
220229
case _:
221230
assert_never(event.type)

0 commit comments

Comments
 (0)