A first try at error handling in the Downloader
authorIngo Ruhnke <grumbel@gmail.com>
Tue, 26 Aug 2014 20:30:22 +0000 (22:30 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Tue, 26 Aug 2014 22:57:46 +0000 (00:57 +0200)
This isn't fully working, as skipping the .then() callbacks skips over
important cleanup and leads to failure further down the line.

src/addon/downloader.cpp
src/addon/downloader.hpp
src/gui/menu_manager.cpp

index 14d4dc4..fd8320b 100644 (file)
@@ -282,7 +282,6 @@ Downloader::update()
           TransferStatusPtr status = (*it)->get_status();
           m_transfers.erase(it);
 
-          status->status = TransferStatus::COMPLETED;
           for(auto& callback : status->callbacks)
           {
             callback();
index 64d2384..de11557 100644 (file)
@@ -34,21 +34,20 @@ public:
 
 public:
   TransferId id;
-  Status status;
+  std::vector<std::function<void ()> > callbacks;
+
   int dltotal;
   int dlnow;
   int ultotal;
   int ulnow;
-  std::vector<std::function<void ()> > callbacks;
 
   TransferStatus(TransferId id_) :
     id(id_),
-    status(RUNNING),
+    callbacks(),
     dltotal(0),
     dlnow(0),
     ultotal(0),
-    ulnow(0),
-    callbacks()
+    ulnow(0)
   {}
 
   void then(const std::function<void ()>& callback)
index a3c4b8e..009a10a 100644 (file)
@@ -26,6 +26,7 @@
 #include "supertux/globals.hpp"
 #include "supertux/menu/menu_storage.hpp"
 #include "supertux/timer.hpp"
+#include "util/gettext.hpp"
 #include "util/log.hpp"
 #include "video/drawing_context.hpp"
 
@@ -207,7 +208,17 @@ MenuManager::draw(DrawingContext& context)
   {
     if (m_dialog)
     {
-      m_dialog->update();
+      try
+      {
+        m_dialog->update();
+      }
+      catch(const std::exception& err)
+      {
+        m_dialog = std::unique_ptr<Dialog>(new Dialog);
+        m_dialog->set_text(_("Error:\n") + err.what());
+        m_dialog->add_button(_("Ok"));
+      }
+
       m_dialog->draw(context);
     }
     else if (current_menu())