Ignore:
Timestamp:
Apr 17, 2017 4:30:10 PM (12 months ago)
Author:
krzywon
Branches:
master, ESS_GUI, ESS_GUI_CategroyManager, ESS_GUI_Pr, ESS_GUI_better_batch, ESS_GUI_corf, ESS_GUI_model_editor, ESS_GUI_py2_OLD, ESS_GUI_sum_editor, SVCC-1, SasView-664, costrafo411, ticket-1094-headless, ticket-818, ticket-976, ticket885, ticket885b, unittest-saveload, win64bit_conda_vm
Children:
ad92c5a
Parents:
8ffafd1
git-author:
Jeff Krzywon <krzywon@…> (04/17/17 16:30:10)
git-committer:
krzywon <krzywon@…> (04/17/17 16:30:10)
Message:

Added a 4th data loader exception for generic readers that cannot open file.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/loader.py

    r278ddee rda8bb53  
    2525import logging 
    2626import time 
     27import mimetypes 
    2728from zipfile import ZipFile 
    2829from sas.sascalc.data_util.registry import ExtensionRegistry 
    2930# Default readers are defined in the readers sub-module 
    3031import readers 
    31 from loader_exceptions import NoKnownLoaderException, FileContentsException 
     32from loader_exceptions import NoKnownLoaderException, FileContentsException,\ 
     33    DefaultReaderException 
    3234from readers import ascii_reader 
    3335from readers import cansas_reader 
     
    7577            ascii_loader = ascii_reader.Reader() 
    7678            return ascii_loader.read(path) 
    77         except FileContentsException: 
    78             pass  # try the cansas XML reader 
     79        except DefaultReaderException: 
     80            pass  # Loader specific error to try the cansas XML reader 
    7981        try: 
    8082            cansas_loader = cansas_reader.Reader() 
    8183            return cansas_loader.read(path) 
     84        except DefaultReaderException: 
     85            pass  # Loader specific error to try the cansas NeXuS reader 
    8286        except FileContentsException: 
    83             pass  # try the cansas NeXuS reader 
     87            # TODO: Handle errors properly 
     88            pass 
     89        except Exception as csr: 
     90            # TODO: Modify cansas reader to throw DefaultReaderException 
     91            pass 
    8492        try: 
    8593            cansas_nexus_loader = cansas_reader_HDF5.Reader() 
    8694            return cansas_nexus_loader.read(path) 
    87         except FileContentsException: 
     95        except DefaultReaderException: 
    8896            logging.errors("No default loader can load the data") 
    8997            # No known reader available. Give up and throw an error 
     
    92100            msg += "Traceback:\n%s" % e.message 
    93101            raise NoKnownLoaderException, msg 
     102        except FileContentsException: 
     103            # TODO: Handle error(s) properly 
     104            pass 
    94105 
    95106    def find_plugins(self, dir): 
Note: See TracChangeset for help on using the changeset viewer.