Ignore:
Timestamp:
Aug 21, 2017 8:16:13 AM (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:
7b15990
Parents:
44daa56
Message:

Make suggested changes

File:
1 edited

Legend:

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

    r3a81cd9 rdcb91cf  
    6969        readers if no reader was registered for the file's extension. 
    7070        """ 
     71        # Gets set to a string if the file has an associated reader that fails 
     72        msg_from_reader = None 
    7173        try: 
    7274            return super(Registry, self).load(path, format=format) 
    7375        except NoKnownLoaderException as nkl_e: 
    74             pass  # try the ASCII reader 
     76            pass  # Try the ASCII reader 
    7577        except FileContentsException as fc_exc: 
    76             # File has an associated reader but it failed 
    77             raise RuntimeError(fc_exc.message) 
     78            # File has an associated reader but it failed. 
     79            # Save the error message to display later, but try the 3 default loaders 
     80            msg_from_reader = fc_exc.message 
    7881        except Exception: 
    7982            pass 
    8083 
    81         # File has no associated reader - try the ASCII reader 
     84        # File has no associated reader, or the associated reader failed. 
     85        # Try the ASCII reader 
    8286        try: 
    8387            ascii_loader = ascii_reader.Reader() 
     
    8690            pass  # Loader specific error to try the cansas XML reader 
    8791        except FileContentsException as e: 
    88             raise RuntimeError(e.message) 
     92            if msg_from_reader is None: 
     93                raise RuntimeError(e.message) 
    8994 
    9095        # ASCII reader failed - try CanSAS xML reader 
     
    95100            pass  # Loader specific error to try the NXcanSAS reader 
    96101        except FileContentsException as e: 
    97             raise RuntimeError(e.message) 
    98         except Exception as csr: 
     102            if msg_from_reader is None: 
     103                raise RuntimeError(e.message) 
     104        except Exception: 
    99105            pass 
    100106 
     
    106112            logging.error("No default loader can load the data") 
    107113            # No known reader available. Give up and throw an error 
    108             msg = "\n\tUnknown data format: %s.\n\tThe file is not a " % path 
    109             msg += "known format that can be loaded by SasView.\n" 
    110             raise NoKnownLoaderException(msg) 
     114            if msg_from_reader is None: 
     115                msg = "\nUnknown data format: {}.\nThe file is not a ".format(path) 
     116                msg += "known format that can be loaded by SasView.\n" 
     117                raise NoKnownLoaderException(msg) 
     118            else: 
     119                # Associated reader and default readers all failed. 
     120                # Show error message from associated reader 
     121                raise RuntimeError(msg_from_reader) 
    111122        except FileContentsException as e: 
    112             raise RuntimeError(e.message) 
     123            err_msg = msg_from_reader if msg_from_reader is not None else e.message 
     124            raise RuntimeError(err_msg) 
    113125 
    114126    def find_plugins(self, dir): 
Note: See TracChangeset for help on using the changeset viewer.