Navigation Menu

Skip to content

Commit

Permalink
A first try at error handling in the Downloader
Browse files Browse the repository at this point in the history
This isn't fully working, as skipping the .then() callbacks skips over
important cleanup and leads to failure further down the line.
  • Loading branch information
Grumbel committed Aug 26, 2014
1 parent d6220ed commit 84c71f1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/addon/downloader.cpp
Expand Up @@ -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();
Expand Down
9 changes: 4 additions & 5 deletions src/addon/downloader.hpp
Expand Up @@ -34,21 +34,20 @@ class TransferStatus

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)
Expand Down
13 changes: 12 additions & 1 deletion src/gui/menu_manager.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 84c71f1

Please sign in to comment.