Changeset 7f75a3f in sasview for src/sas/sascalc/dataloader/readers


Ignore:
Timestamp:
Apr 5, 2017 11:08:59 AM (8 years ago)
Author:
krzywon
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:
278ddee
Parents:
69400ec
git-author:
Jeff Krzywon <krzywon@…> (04/05/17 11:08:59)
git-committer:
krzywon <krzywon@…> (04/05/17 11:08:59)
Message:

More explicit error messages when file loading fails. see #889

Location:
src/sas/sascalc/dataloader/readers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sascalc/dataloader/readers/ascii_reader.py

    r9a5097c r7f75a3f  
    1717import os 
    1818from sas.sascalc.dataloader.data_info import Data1D 
     19from sas.sascalc.dataloader.loader_exceptions import FileContentsException 
    1920 
    2021# Check whether we have a converter available 
     
    173174                if not is_data: 
    174175                    msg = "ascii_reader: x has no data" 
    175                     raise RuntimeError, msg 
     176                    raise FileContentsException, msg 
    176177                # Sanity check 
    177178                if has_error_dy == True and not len(ty) == len(tdy): 
    178179                    msg = "ascii_reader: y and dy have different length" 
    179                     raise RuntimeError, msg 
     180                    raise FileContentsException, msg 
    180181                if has_error_dx == True and not len(tx) == len(tdx): 
    181182                    msg = "ascii_reader: y and dy have different length" 
    182                     raise RuntimeError, msg 
     183                    raise FileContentsException, msg 
    183184                # If the data length is zero, consider this as 
    184185                # though we were not able to read the file. 
    185186                if len(tx) == 0: 
    186                     raise RuntimeError, "ascii_reader: could not load file" 
     187                    raise FileContentsException, "ascii_reader: could not load file" 
    187188 
    188189                #Let's re-order the data to make cal. 
  • src/sas/sascalc/dataloader/readers/cansas_reader.py

    r8434365 r7f75a3f  
    2929from sas.sascalc.dataloader.readers.xml_reader import XMLreader 
    3030from sas.sascalc.dataloader.readers.cansas_constants import CansasConstants, CurrentLevel 
     31from sas.sascalc.dataloader.loader_exceptions import FileContentsException 
    3132 
    3233# The following 2 imports *ARE* used. Do not remove either. 
     
    534535 
    535536        # Load in xml file and get the cansas version from the header 
    536         self.set_xml_file(xml_file) 
     537        from lxml import etree 
     538        try: 
     539            self.set_xml_file(xml_file) 
     540        except etree.XMLSyntaxError: 
     541            msg = "Cansas cannot load this file" 
     542            raise FileContentsException, msg 
    537543        self.cansas_version = self.xmlroot.get("version", "1.0") 
    538544 
  • src/sas/sascalc/dataloader/readers/cansas_reader_HDF5.py

    rc94280c r7f75a3f  
    1313    TransmissionSpectrum, Detector 
    1414from sas.sascalc.dataloader.data_info import combine_data_info_with_plottable 
     15from sas.sascalc.dataloader.loader_exceptions import FileContentsException 
    1516 
    1617 
     
    7576            if extension in self.ext or self.allow_all: 
    7677                # Load the data file 
    77                 self.raw_data = h5py.File(filename, 'r') 
     78                try: 
     79                    self.raw_data = h5py.File(filename, 'r') 
     80                except Exception as e: 
     81                    raise FileContentsException, e 
    7882                # Read in all child elements of top level SASroot 
    7983                self.read_children(self.raw_data, []) 
  • src/sas/sascalc/dataloader/readers/xml_reader.py

    ra235f715 r7f75a3f  
    7070            self.xmldoc = etree.parse(self.xml, parser=PARSER) 
    7171            self.xmlroot = self.xmldoc.getroot() 
    72         except etree.XMLSyntaxError as xml_error: 
    73             logging.info(xml_error) 
     72        except etree.XMLSyntaxError: 
     73            raise 
    7474        except Exception: 
    7575            self.xml = None 
Note: See TracChangeset for help on using the changeset viewer.