We have an application that watches a directory and looks for .csv files being created there. Upon detecting a new file, the csv is read using readcell and a function is called using the arguments found in the csv.
Almost always this works just fine, but on some rare occasions it seems like readcell does not return anything.
The code it executes in is really simple:
try
if LOGGING
logging_message = sprintf('Trying to read command csv');
write_info(diary_file_id, logging_message);
end
input_csv = readcell(txt_filename);
dir_to_process = input_csv{5};
type_to_process = input_csv{6};
dir_to_process = replace(dir_to_process, '\', '/');
if LOGGING
logging_message = sprintf('Command csv gave dir_to_process: %s and type_to_process: %s', dir_to_process, type_to_process);
write_info(diary_file_id, logging_message);
end
catch ME
logging_message = sprintf('Failed with error message: %s',ME.message);
write_error(diary_file_id, logging_message);
write_error(diary_file_id, getReport(ME, 'extended', 'hyperlinks', 'off'))
if DEBUG
rethrow(ME)
end
end
As you can see it writes output to a logfile. Such a logfile looks like this when the problem occurs:
2020-11-16_17.58.21.879 MATLAB INFO | Eventhandler received a file
2020-11-16_17.58.21.894 MATLAB INFO | Received command file name 2020-11-16_17.49.51.csv
2020-11-16_17.58.26.917 MATLAB INFO | Trying to read command csv
The program does not return and does not return an error because those are also logged.
This is what an error can look like in the logging file for instance with an empty csv file:
2020-11-18_09.00.32.929 MATLAB INFO | Eventhandler received a file
2020-11-18_09.00.32.934 MATLAB INFO | Received command file name empty.csv
2020-11-18_09.00.37.940 MATLAB INFO | Trying to read command csv
2020-11-18_09.00.37.979 MATLAB ERROR | Failed with error message: Index exceeds the number of array elements (0).
2020-11-18_09.00.37.985 MATLAB ERROR | Index exceeds the number of array elements (0).
Error in eventhandler_changed (line 37)
dir_to_process = input_csv{5};
In order to recreate this problem I've tried to:
- Open the file in a different program simultaniously
- Pass bogus arguments in the csv
- Pass no arguments in the csv
But with no succes. I've also tried looking at the readcell source code but this is all I can see:
try
func = matlab.io.internal.functions.FunctionStore.getFunctionByName('readcell');
C = func.validateAndExecute(filename,varargin{:});
catch ME
throw(ME);
end
Which clearly shows that an error should be throwns if it crashes, but it definitely does not seem to do that in my case.