Skip to content

Commit 0f37e74

Browse files
authored
Merge pull request #1124 from effigies/fix/stopiteration-heisenbug
fix: Catch StopIteration on directory walk
2 parents cd62b38 + a81db53 commit 0f37e74

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/bids/layout/index.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,14 @@ def _index_dir(self, path, config, force=None):
208208
for c in config:
209209
config_entities.update(c.entities)
210210

211-
212211
# Get lists of 1st-level subdirectories and files in the path directory
213-
_, dirnames, filenames = next(path.fs.walk(path.path))
214-
212+
try:
213+
_, dirnames, filenames = next(path.fs.walk(path.path))
214+
except StopIteration:
215+
# It's unclear when this gets hit, but tests will occasionally fail here.
216+
# Hopefully this only occurs when we enter an empty directory,
217+
# but even if not, there's nothing else to do in this case.
218+
return [], []
215219

216220
# Symbolic links are returned as filenames even if they point to directories
217221
# Temporary list to store symbolic links that need to be removed from filenames

0 commit comments

Comments
 (0)