@contextmanager
def catch_io_errors(ifile, out, single_out, force, corrupt_files):
 try:
  (yield)
 except (IOError, OSError, ValueError) as error:
  log_error('** ERROR: {error}', error=str(error))
  log_error('** Failed on {name}: ', name=ifile)
  if (not single_out):
   os.remove(out.name)
  if (not force):
   log_error('** Exiting!')
   sys.exit(1)
  else:
   log_error('*** Skipping error file, moving on...')
   corrupt_files.append(ifile)

@ contextmanager def catch_io_errors ( ifile , out , single_out , force , corrupt_files ) : try : ( yield ) except ( IOError , OSError , ValueError ) as error : log_error ( '** ERROR: {error}' , error = str ( error ) ) log_error ( '** Failed on {name}: ' , name = ifile ) if ( not single_out ) : os . remove ( out . name ) if ( not force ) : log_error ( '** Exiting!' ) sys . exit ( 1 ) else : log_error ( '*** Skipping error file, moving on...' ) corrupt_files . append ( ifile )
context manager to do boilerplate handling of ioerrors .