make really sure load_mupa has a file to parse.
[mussa.git] / alg / mussa.cpp
index f87673a35a2c0afb614530542563b77362d7d78a..6990db7bac926b554651cc151f4959c12c5e9a0e 100644 (file)
@@ -316,8 +316,14 @@ Mussa::load_mupa_file(fs::path para_file_path)
   clear();
 
   // if file was opened, read the parameter values
-  if (fs::exists(para_file_path))
+  if (not fs::exists(para_file_path))
   {
+    throw mussa_load_error("Config File: " + para_file_path.string() + " not found");
+  } else if (fs::is_directory(para_file_path)) {
+    throw mussa_load_error("Config File: " + para_file_path.string() + " is a directory.");
+  } else if (fs::is_empty(para_file_path)) {
+    throw mussa_load_error("Config File: " + para_file_path.string() + " is empty");
+  } else  {
     para_file.open(para_file_path, ios::in);
 
     // what directory is the mupa file in?
@@ -329,7 +335,7 @@ Mussa::load_mupa_file(fs::path para_file_path)
     param = file_data_line.substr(0,split_index);
     value = file_data_line.substr(split_index+1);
     
-    while (!para_file.eof())
+    while (para_file)
     {
       did_seq = false;
       if (param == "ANA_NAME")
@@ -354,7 +360,7 @@ Mussa::load_mupa_file(fs::path para_file_path)
         sub_seq_end = 0;
         seq_params = true;
 
-        while ((!para_file.eof()) && seq_params)
+        while (para_file && seq_params)
         {
           getline(para_file,file_data_line);
           split_index = file_data_line.find(" ");
@@ -405,10 +411,6 @@ Mussa::load_mupa_file(fs::path para_file_path)
     //     << " threshold = " << threshold << endl;
   }
   // no file was loaded, signal error
-  else
-  {
-    throw mussa_load_error("Config File: " + para_file_path.string() + " not found");
-  }
   dirty = true;
 }