Skip to content

Commit

Permalink
FIX: Improve error message when files could not be fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Mar 13, 2019
1 parent 899a16a commit b777b7b
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions templateflow/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,37 @@ def get(template, **kwargs):
template=template, return_type='file', **kwargs)]

# Try plain URL fetch first
for filepath in [p for p in out_file
if p.is_file() and p.stat().st_size == 0]:
s3_missing = [p for p in out_file
if p.is_file() and p.stat().st_size == 0]
for filepath in s3_missing:
_s3_get(filepath)

dl_missing = None
if TF_USE_DATALAD:
for filepath in [p for p in out_file if not p.is_file()]:
dl_missing = [p for p in out_file if not p.is_file()]
for filepath in dl_missing:
_datalad_get(filepath)

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

if any(not_fetched):
raise RuntimeError(
"Could not fetch template files: %s" % ', '.join(not_fetched))
msg = "Could not fetch template files: %s." % ', '.join(not_fetched)
if dl_missing and not TF_USE_DATALAD:
msg += """\
The $TEMPLATEFLOW_HOME folder %s seems to contain an initiated DataLad \
dataset, but the environment variable $TEMPLATEFLOW_USE_DATALAD is not \
set or set to one of (false, off, 0). Please set $TEMPLATEFLOW_USE_DATALAD \
on (possible values: true, on, 1).""" % TF_LAYOUT.root

if s3_missing and TF_USE_DATALAD:
msg += """\
The $TEMPLATEFLOW_HOME folder %s seems to contain an plain \
dataset, but the environment variable $TEMPLATEFLOW_USE_DATALAD is \
set to one of (true, on, 1). Please set $TEMPLATEFLOW_USE_DATALAD \
off (possible values: false, off, 0).""" % TF_LAYOUT.root

raise RuntimeError(msg)

if len(out_file) == 1:
return out_file[0]
Expand Down

0 comments on commit b777b7b

Please sign in to comment.