Skip to content

Commit b777b7b

Browse files
committed
FIX: Improve error message when files could not be fetched
As per #8 (comment)
1 parent 899a16a commit b777b7b

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

templateflow/api.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,37 @@ def get(template, **kwargs):
2626
template=template, return_type='file', **kwargs)]
2727

2828
# Try plain URL fetch first
29-
for filepath in [p for p in out_file
30-
if p.is_file() and p.stat().st_size == 0]:
29+
s3_missing = [p for p in out_file
30+
if p.is_file() and p.stat().st_size == 0]
31+
for filepath in s3_missing:
3132
_s3_get(filepath)
3233

34+
dl_missing = None
3335
if TF_USE_DATALAD:
34-
for filepath in [p for p in out_file if not p.is_file()]:
36+
dl_missing = [p for p in out_file if not p.is_file()]
37+
for filepath in dl_missing:
3538
_datalad_get(filepath)
3639

3740
not_fetched = [p for p in out_file
3841
if not p.is_file() or p.stat().st_size == 0]
3942

4043
if any(not_fetched):
41-
raise RuntimeError(
42-
"Could not fetch template files: %s" % ', '.join(not_fetched))
44+
msg = "Could not fetch template files: %s." % ', '.join(not_fetched)
45+
if dl_missing and not TF_USE_DATALAD:
46+
msg += """\
47+
The $TEMPLATEFLOW_HOME folder %s seems to contain an initiated DataLad \
48+
dataset, but the environment variable $TEMPLATEFLOW_USE_DATALAD is not \
49+
set or set to one of (false, off, 0). Please set $TEMPLATEFLOW_USE_DATALAD \
50+
on (possible values: true, on, 1).""" % TF_LAYOUT.root
51+
52+
if s3_missing and TF_USE_DATALAD:
53+
msg += """\
54+
The $TEMPLATEFLOW_HOME folder %s seems to contain an plain \
55+
dataset, but the environment variable $TEMPLATEFLOW_USE_DATALAD is \
56+
set to one of (true, on, 1). Please set $TEMPLATEFLOW_USE_DATALAD \
57+
off (possible values: false, off, 0).""" % TF_LAYOUT.root
58+
59+
raise RuntimeError(msg)
4360

4461
if len(out_file) == 1:
4562
return out_file[0]

0 commit comments

Comments
 (0)