@@ -260,7 +260,6 @@ def main():
260
260
"""Entry point"""
261
261
from nipype import logging as nlogging
262
262
from multiprocessing import set_start_method , Process , Manager
263
- from ..viz .reports import generate_reports
264
263
from ..utils .bids import write_derivative_description
265
264
set_start_method ('forkserver' )
266
265
@@ -384,8 +383,6 @@ def before_send(event, hints):
384
383
nlogging .getLogger ('nipype.interface' ).setLevel (log_level )
385
384
nlogging .getLogger ('nipype.utils' ).setLevel (log_level )
386
385
387
- errno = 0
388
-
389
386
# Call build_workflow(opts, retval)
390
387
with Manager () as mgr :
391
388
retval = mgr .dict ()
@@ -395,9 +392,9 @@ def before_send(event, hints):
395
392
396
393
retcode = p .exitcode or retval .get ('return_code' , 0 )
397
394
398
- bids_dir = retval .get ('bids_dir' )
399
- output_dir = retval .get ('output_dir' )
400
- work_dir = retval .get ('work_dir' )
395
+ bids_dir = Path ( retval .get ('bids_dir' ) )
396
+ output_dir = Path ( retval .get ('output_dir' ) )
397
+ work_dir = Path ( retval .get ('work_dir' ) )
401
398
plugin_settings = retval .get ('plugin_settings' , None )
402
399
subject_list = retval .get ('subject_list' , None )
403
400
fmriprep_wf = retval .get ('workflow' , None )
@@ -436,32 +433,48 @@ def before_send(event, hints):
436
433
sentry_sdk .add_breadcrumb (message = 'fMRIPrep started' , level = 'info' )
437
434
sentry_sdk .capture_message ('fMRIPrep started' , level = 'info' )
438
435
436
+ errno = 1 # Default is error exit unless otherwise set
439
437
try :
440
438
fmriprep_wf .run (** plugin_settings )
441
- except RuntimeError as e :
442
- errno = 1
443
- if "Workflow did not execute cleanly" not in str (e ):
444
- sentry_sdk .capture_exception (e )
445
- raise
439
+ except Exception as e :
440
+ if not opts .notrack :
441
+ from ..utils .sentry import process_crashfile
442
+ crashfolders = [output_dir / 'fmriprep' / 'sub-{}' .format (s ) / 'log' / run_uuid
443
+ for s in subject_list ]
444
+ for crashfolder in crashfolders :
445
+ for crashfile in crashfolder .glob ('crash*.*' ):
446
+ process_crashfile (crashfile )
447
+
448
+ if "Workflow did not execute cleanly" not in str (e ):
449
+ sentry_sdk .capture_exception (e )
450
+ logger .critical ('fMRIPrep failed: %s' , e )
451
+ raise
446
452
else :
447
453
if opts .run_reconall :
448
454
from templateflow import api
449
455
from niworkflows .utils .misc import _copy_any
450
456
dseg_tsv = str (api .get ('fsaverage' , suffix = 'dseg' , extensions = ['.tsv' ]))
451
457
_copy_any (dseg_tsv ,
452
- str (Path ( output_dir ) / 'fmriprep' / 'desc-aseg_dseg.tsv' ))
458
+ str (output_dir / 'fmriprep' / 'desc-aseg_dseg.tsv' ))
453
459
_copy_any (dseg_tsv ,
454
- str (Path (output_dir ) / 'fmriprep' / 'desc-aparcaseg_dseg.tsv' ))
460
+ str (output_dir / 'fmriprep' / 'desc-aparcaseg_dseg.tsv' ))
461
+ errno = 0
455
462
logger .log (25 , 'fMRIPrep finished without errors' )
463
+ if not opts .notrack :
464
+ sentry_sdk .capture_message ('fMRIPrep finished without errors' ,
465
+ level = 'info' )
456
466
finally :
467
+ from niworkflows .reports import generate_reports
457
468
# Generate reports phase
458
- errno + = generate_reports (subject_list , output_dir , work_dir , run_uuid ,
459
- sentry_sdk = sentry_sdk )
460
- write_derivative_description (bids_dir , str ( Path ( output_dir ) / 'fmriprep' ) )
469
+ failed_reports = generate_reports (
470
+ subject_list , output_dir , work_dir , run_uuid , packagename = 'fmriprep' )
471
+ write_derivative_description (bids_dir , output_dir / 'fmriprep' )
461
472
462
- if not opts .notrack and errno == 0 :
463
- sentry_sdk .capture_message ('fMRIPrep finished without errors' , level = 'info' )
464
- sys .exit (int (errno > 0 ))
473
+ if failed_reports and not opts .notrack :
474
+ sentry_sdk .capture_message (
475
+ 'Report generation failed for %d subjects' % failed_reports ,
476
+ level = 'error' )
477
+ sys .exit (int ((errno + failed_reports ) > 0 ))
465
478
466
479
467
480
def validate_input_dir (exec_env , bids_dir , participant_label ):
@@ -574,9 +587,9 @@ def build_workflow(opts, retval):
574
587
575
588
from nipype import logging , config as ncfg
576
589
from niworkflows .utils .bids import collect_participants
590
+ from niworkflows .reports import generate_reports
577
591
from ..__about__ import __version__
578
592
from ..workflows .base import init_fmriprep_wf
579
- from ..viz .reports import generate_reports
580
593
581
594
logger = logging .getLogger ('nipype.workflow' )
582
595
@@ -734,7 +747,8 @@ def build_workflow(opts, retval):
734
747
run_uuid = opts .run_uuid
735
748
retval ['run_uuid' ] = run_uuid
736
749
retval ['return_code' ] = generate_reports (
737
- subject_list , str (output_dir ), str (work_dir ), run_uuid )
750
+ subject_list , output_dir , work_dir , run_uuid ,
751
+ packagename = 'fmriprep' )
738
752
return retval
739
753
740
754
# Build main workflow
0 commit comments