Ignore:
Timestamp:
Feb 14, 2015 11:16:03 AM (9 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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
10a483f
Parents:
b3133fd
Message:

Modified data loading error messages to be much more specific and
include information in the console log about the specific errors
generated.

The cansas reader is now loading non-standard units (ie counts), but
shows a specific error message about the issue.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/guiframe/local_perspectives/data_loader/data_loader.py

    r7a04dbb rb3efb7d  
    171171                                  file) for file in os.listdir(path)] 
    172172    
     173    def _process_data_and_errors(self, item, p_file, output, message): 
     174        """ 
     175        Check to see if data set loaded with any errors. If so, append to 
     176            error message to be sure user knows the issue. 
     177        """ 
     178        data_error = False 
     179        for error_data in item.errors: 
     180            data_error = True 
     181            message += "\tError: {0}\n".format(error_data) 
     182        data = self.parent.create_gui_data(item, p_file) 
     183        output[data.id] = data 
     184        return output, message, data_error 
     185    
    173186    def get_data(self, path, format=None): 
    174187        """ 
     
    178191        output = {} 
    179192        any_error = False 
     193        data_error = False 
    180194        error_message = "" 
    181195        for p_file in path: 
    182196            info = "info" 
    183197            basename  = os.path.basename(p_file) 
    184             root, extension = os.path.splitext(basename) 
     198            _, extension = os.path.splitext(basename) 
    185199            if extension.lower() in EXTENSIONS: 
    186200                any_error = True 
     
    194208         
    195209            try: 
     210                message = "Loading Data... " + str(p_file) + "\n" 
     211                self.load_update(output=output, message=message, info=info) 
    196212                temp =  self.loader.load(p_file, format) 
    197213                if temp.__class__.__name__ == "list": 
    198214                    for item in temp: 
    199                         data = self.parent.create_gui_data(item, p_file) 
    200                         output[data.id] = data 
     215                        output, error_message, data_error = \ 
     216                            self._process_data_and_errors(item,  
     217                                                          p_file,  
     218                                                          output,  
     219                                                          error_message) 
    201220                else: 
    202                     data = self.parent.create_gui_data(temp, p_file) 
    203                     output[data.id] = data 
    204                 message = "Loading Data..." + str(p_file) + "\n" 
    205                 self.load_update(output=output, message=message, info=info) 
     221                    output, error_message, data_error = \ 
     222                            self._process_data_and_errors(temp,  
     223                                                          p_file,  
     224                                                          output,  
     225                                                          error_message) 
    206226            except: 
    207227                any_error = True 
    208                 if error_message == "": 
    209                      error = "Error: " + str(sys.exc_value) + "\n" 
    210                      error += "while loading Data: \n%s\n" % str(p_file) 
    211                      error_message = "The data file you selected could not be loaded.\n" 
    212                      error_message += "Make sure the content of your file" 
    213                      error_message += " is properly formatted.\n\n" 
    214                      error_message += "When contacting the DANSE team, mention the" 
    215                      error_message += " following:\n%s" % str(error) 
    216                 else: 
    217                      error_message += "%s\n"% str(p_file) 
    218                 info = "error" 
    219                 self.load_update(output=output, message=error_message,  
     228        if any_error or error_message != "": 
     229            if error_message == "": 
     230                error = "Error: " + str(sys.exc_value) + "\n" 
     231                error += "while loading Data: \n%s\n" % str(p_file) 
     232                error_message = "The data file you selected could not be loaded.\n" 
     233                error_message += "Make sure the content of your file" 
     234                error_message += " is properly formatted.\n\n" 
     235                error_message += "When contacting the DANSE team, mention the" 
     236                error_message += " following:\n%s" % str(error) 
     237            elif data_error: 
     238                base_message = "Errors occurred while loading {0}\n".format(p_file) 
     239                base_message += "The data file loaded but with errors.\n" 
     240                error_message = base_message + error_message 
     241            else: 
     242                error_message += "%s\n"% str(p_file) 
     243            info = "error" 
     244            self.load_update(output=output, message=error_message,  
    220245                                  info=info) 
    221246                 
    222         message = "Loading Data Complete! " 
     247        else: 
     248            message = "Loading Data Complete! " 
    223249        message += log_msg 
    224         if error_message != "": 
    225             info = 'error' 
    226250        self.load_complete(output=output, error_message=error_message, 
    227251                       message=message, path=path, info=info) 
Note: See TracChangeset for help on using the changeset viewer.