Ignore:
Timestamp:
Apr 17, 2017 2:30:10 PM (7 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:
ad92c5a
Parents:
8ffafd1
git-author:
Jeff Krzywon <krzywon@…> (04/17/17 14:30:10)
git-committer:
krzywon <krzywon@…> (04/17/17 14: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/readers/ascii_reader.py

    r8ffafd1 rda8bb53  
    1717from sas.sascalc.dataloader.file_reader_base_class import FileReader 
    1818from sas.sascalc.dataloader.data_info import DataInfo, plottable_1D 
     19from sas.sascalc.dataloader.loader_exceptions import FileContentsException,\ 
     20    DefaultReaderException 
    1921 
    2022logger = logging.getLogger(__name__) 
     
    110112                line_no += 1 
    111113            except ValueError: 
     114                # ValueError is raised when non numeric strings conv. to float 
    112115                # It is data and meet non - number, then stop reading 
    113116                if is_data: 
     
    121124                # Reset # of lines of data candidates 
    122125                candidate_lines = 0 
    123             except Exception: 
    124                 # Handle any unexpected exceptions 
    125                 raise 
    126126 
    127127        if not is_data: 
    128             # TODO: Check file extension - primary reader, throw error. 
    129             # TODO: Secondary check, pass and try next reader 
    130             msg = "ascii_reader: x has no data" 
    131             raise RuntimeError(msg) 
     128            self.set_all_to_none() 
     129            if self.extension in self.ext: 
     130                msg = "ASCII Reader error: Fewer than five Q data points found " 
     131                msg += "in {}.".format(filepath) 
     132                raise FileContentsException(msg) 
     133            else: 
     134                msg = "ASCII Reader could not load the file {}".format(filepath) 
     135                raise DefaultReaderException(msg) 
    132136        # Sanity check 
    133137        if has_error_dy and not len(self.current_dataset.y) == \ 
    134138                len(self.current_dataset.dy): 
    135             msg = "ascii_reader: y and dy have different length" 
    136             raise RuntimeError(msg) 
     139            msg = "ASCII Reader error: Number of I and dI data points are" 
     140            msg += " different in {}.".format(filepath) 
     141            # TODO: Add error to self.current_datainfo.errors instead? 
     142            self.set_all_to_none() 
     143            raise FileContentsException(msg) 
    137144        if has_error_dx and not len(self.current_dataset.x) == \ 
    138145                len(self.current_dataset.dx): 
    139             msg = "ascii_reader: y and dy have different length" 
    140             raise RuntimeError(msg) 
    141         # If the data length is zero, consider this as 
    142         # though we were not able to read the file. 
    143         if len(self.current_dataset.x) < 1: 
    144             raise RuntimeError("ascii_reader: could not load file") 
     146            msg = "ASCII Reader error: Number of Q and dQ data points are" 
     147            msg += " different in {}.".format(filepath) 
     148            # TODO: Add error to self.current_datainfo.errors instead? 
     149            self.set_all_to_none() 
     150            raise FileContentsException(msg) 
    145151 
    146         # Data 
     152        # Remove any point where Q == 0 
    147153        x = self.current_dataset.x 
    148154        self.current_dataset.x = self.current_dataset.x[x != 0] 
Note: See TracChangeset for help on using the changeset viewer.