Skip to content

Commit 0fc645c

Browse files
committed
add logger warning
1 parent 65a1583 commit 0fc645c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

cubids/cubids.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,7 @@ def _build_intendedfor_index(self):
10831083
for path in Path(self.path).rglob("sub-*/**/fmap/*.json"):
10841084
metadata = utils.get_sidecar_metadata(str(path))
10851085
if metadata == "Erroneous sidecar":
1086+
print(f"Warning: Failed to parse sidecar metadata from '{path}'.")
10861087
continue
10871088
if_list = metadata.get("IntendedFor")
10881089
items = listify(if_list)
@@ -1094,6 +1095,7 @@ def _build_intendedfor_index(self):
10941095
for path in Path(self.path).rglob("sub-*/**/perf/*_m0scan.json"):
10951096
metadata = utils.get_sidecar_metadata(str(path))
10961097
if metadata == "Erroneous sidecar":
1098+
print(f"Warning: Failed to parse sidecar metadata from '{path}'.")
10971099
continue
10981100
if_list = metadata.get("IntendedFor")
10991101
items = listify(if_list)

cubids/workflows.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ def _link_or_copy(src_path, dst_path):
136136
if os.path.exists(dest_path):
137137
try:
138138
os.remove(dest_path)
139-
except Exception: # noqa: BLE001
140-
pass
139+
except Exception as e:
140+
logger.warning(
141+
f"Failed to remove existing file '{dest_path}': {e}. "
142+
"The file may be overwritten or cause conflicts."
143+
)
141144
# Try to find source file in the provided file list
142145
try:
143146
source_path = None
@@ -153,8 +156,12 @@ def _link_or_copy(src_path, dst_path):
153156
if source_path:
154157
# Always copy (not link) to protect the original file from modification
155158
shutil.copy2(source_path, dest_path)
156-
except Exception: # noqa: BLE001
157-
pass
159+
except Exception as e:
160+
source_info = source_path if source_path else "unknown location"
161+
logger.warning(
162+
f"Failed to copy '{filename}' from '{source_info}' to '{dest_path}': {e}. "
163+
"The file may be missing or inaccessible."
164+
)
158165

159166
# If participants.tsv exists in the temp BIDS root, filter to current subject
160167
participants_tsv_path = os.path.join(temporary_bids_dir, "participants.tsv")

0 commit comments

Comments
 (0)