Changeset 8dec7e7 in sasview for src/sas/sascalc


Ignore:
Timestamp:
Jul 27, 2017 12:13:00 PM (7 years ago)
Author:
lewis
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
0615d54
Parents:
9d786e5
Message:

Raise DefaultReaderException? in NXcanSAS reader and handle correctly

Location:
src/sas/sascalc/dataloader
Files:
3 edited

Legend:

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

    r3ece5dd r8dec7e7  
    8585            # TODO: handle error 
    8686            raise RuntimeError(e) 
    87             pass 
    8887        try: 
    8988            cansas_loader = cansas_reader.Reader() 
     
    9493            # TODO: Handle errors properly 
    9594            raise RuntimeError(e) 
    96             pass 
    9795        except Exception as csr: 
    9896            # TODO: Modify cansas reader to throw DefaultReaderException 
     
    10199            cansas_nexus_loader = cansas_reader_HDF5.Reader() 
    102100            return cansas_nexus_loader.read(path) 
    103         except DefaultReaderException: 
    104             logging.errors("No default loader can load the data") 
     101        except DefaultReaderException as e: 
     102            logging.error("No default loader can load the data") 
    105103            # No known reader available. Give up and throw an error 
    106104            msg = "\n\tUnknown data format: %s.\n\tThe file is not a " % path 
    107105            msg += "known format that can be loaded by SasView.\n" 
    108             msg += "Traceback:\n%s" % e.message 
    109106            raise NoKnownLoaderException, msg 
    110         except FileContentsException: 
     107        except FileContentsException as e: 
    111108            # TODO: Handle error(s) properly 
    112             pass 
     109            raise RuntimeError(e) 
    113110 
    114111    def find_plugins(self, dir): 
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    r0b79323 r8dec7e7  
    108108 
    109109        basename, _ = os.path.splitext(os.path.basename(xml_file)) 
    110         # Raises FileContentsException - handled by superclass 
    111         self.load_file_and_schema(xml_file, schema_path) 
    112         self.current_datainfo = DataInfo() 
     110 
    113111        try: 
     112            # Raises FileContentsException 
     113            self.load_file_and_schema(xml_file, schema_path) 
     114            self.current_datainfo = DataInfo() 
    114115            # Raises FileContentsException if file doesn't meet CanSAS schema 
    115116            self.is_cansas(self.extension) 
  • src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py

    r9d786e5 r8dec7e7  
    1313    TransmissionSpectrum, Detector 
    1414from sas.sascalc.dataloader.data_info import combine_data_info_with_plottable 
    15 from sas.sascalc.dataloader.loader_exceptions import FileContentsException 
     15from sas.sascalc.dataloader.loader_exceptions import FileContentsException, DefaultReaderException 
    1616from sas.sascalc.dataloader.file_reader_base_class import FileReader 
    1717 
     
    7878                    self.raw_data = h5py.File(filename, 'r') 
    7979                except Exception as e: 
    80                     raise FileContentsException, e 
     80                    if extension not in self.ext: 
     81                        msg = "CanSAS2.0 HDF5 Reader could not load file {}".format(basename + extension) 
     82                        raise DefaultReaderException(msg) 
     83                    raise FileContentsException(e.message) 
    8184                # Read in all child elements of top level SASroot 
    8285                self.read_children(self.raw_data, []) 
Note: See TracChangeset for help on using the changeset viewer.