From 5b06a8ac101295856148e7b0c4e49087786b855e Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Wed, 7 Dec 2011 18:07:02 +0000
Subject: [PATCH] error handling

---
 Common/GmshMessage.h  |  1 +
 Fltk/onelabWindow.cpp | 24 +++++++++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/Common/GmshMessage.h b/Common/GmshMessage.h
index 10c99dcda9..8d24ef1c16 100644
--- a/Common/GmshMessage.h
+++ b/Common/GmshMessage.h
@@ -76,6 +76,7 @@ class Msg {
   static double &Timer(std::string str){ return _timers[str]; }
   static void PrintTimers();
   static void ResetErrorCounter(){ _warningCount = 0; _errorCount = 0; }
+  static int GetErrorCount(){ return _errorCount; }
   static void PrintErrorCounter(const char *title);
   static double GetValue(const char *text, double defaultval);
   static std::string GetString(const char *text, std::string defaultval);
diff --git a/Fltk/onelabWindow.cpp b/Fltk/onelabWindow.cpp
index 2ee95e1f25..b18fa1d5ec 100644
--- a/Fltk/onelabWindow.cpp
+++ b/Fltk/onelabWindow.cpp
@@ -414,6 +414,19 @@ static bool incrementLoop()
   return ret;
 }
 
+static bool stopOnError(const std::string &client)
+{
+  if(Msg::GetErrorCount() > 0 && !CTX::instance()->expertMode){
+    Msg::ResetErrorCounter();
+    std::string msg
+      (client + " reported an error: do you really want to continue?\n\n"
+       "(To disable this warning in the future, select `Enable expert mode'\n"
+       "in the option dialog.");
+    if(Msg::GetAnswer(msg.c_str(), 1, "Stop", "Continue") == 0) return true;
+  }
+  return false;
+}
+
 void onelab_cb(Fl_Widget *w, void *data)
 {
   if(!data) return;
@@ -442,6 +455,8 @@ void onelab_cb(Fl_Widget *w, void *data)
 
   if(action == "compute") initializeLoop();
 
+  bool stop = false;
+
   do{ // enter computation loop
 
     // the Gmsh client is special: it always gets executed first. (The
@@ -478,7 +493,6 @@ void onelab_cb(Fl_Widget *w, void *data)
           geometry_reload_cb(0, 0);
           if(FlGui::instance()->onelab->meshAuto()){
             mesh_3d_cb(0, 0);
-            // FIXME: check if meshing succeeded
             CreateOutputFile(mshFileName, CTX::instance()->mesh.fileFormat);
           }
         }
@@ -486,13 +500,14 @@ void onelab_cb(Fl_Widget *w, void *data)
           // mesh+save if the mesh file does not exist
           if(FlGui::instance()->onelab->meshAuto()){
             mesh_3d_cb(0, 0);
-            // FIXME: check if meshing succeeded
             CreateOutputFile(mshFileName, CTX::instance()->mesh.fileFormat);
           }
         }
         onelab::server::instance()->setChanged(false, "Gmsh");
       }
     }
+    stop = stopOnError("Gmsh");
+    if(stop) break;
     
     // Iterate over all other clients
     for(onelab::server::citer it = onelab::server::instance()->firstClient();
@@ -516,11 +531,14 @@ void onelab_cb(Fl_Widget *w, void *data)
       else if(action == "kill"){
         c->kill();
       }
+      
+      stop = stopOnError(c->getName());
+      if(stop) break;
     }
 
     FlGui::instance()->onelab->rebuildTree();
 
-  } while(action == "compute" && incrementLoop());
+  } while(action == "compute" && incrementLoop() && !stop);
 
   FlGui::instance()->onelab->activate();
   FlGui::instance()->onelab->show();
-- 
GitLab