Skip to content

Commit

Permalink
#5231: Unrecoverable module initialisation errors should be translate…
Browse files Browse the repository at this point in the history
…d to exceptions.
  • Loading branch information
codereader committed Aug 15, 2020
1 parent 6cbf5e5 commit 57a7b05
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
13 changes: 12 additions & 1 deletion include/iradiant.h
Expand Up @@ -55,11 +55,22 @@ class IRadiant :

/**
* Loads and initialises all modules, starting up the
* application.
* application. Might throw a StartupFailure exception
* on unrecoverable errors.
*/
virtual void startup() = 0;

virtual ~IRadiant() {}

// Exception thrown during Radiant startup
class StartupFailure :
public std::runtime_error
{
public:
StartupFailure(const std::string& msg) :
runtime_error(msg)
{}
};
};

}
Expand Down
13 changes: 11 additions & 2 deletions radiant/RadiantApp.cpp
Expand Up @@ -169,8 +169,17 @@ void RadiantApp::onStartupEvent(wxCommandEvent& ev)
_modulesUnloadingHandler = _coreModule->get()->getModuleRegistry().signal_modulesUnloading()
.connect(sigc::mem_fun(this, &RadiantApp::onModulesUnloading));

// Startup the application
_coreModule->get()->startup();
try
{
// Startup the application
_coreModule->get()->startup();
}
catch (const radiant::IRadiant::StartupFailure& ex)
{
// An unhandled exception during module initialisation => display a popup and exit
rError() << "Unhandled Exception: " << ex.what() << std::endl;
wxutil::Messagebox::ShowFatalError(ex.what(), nullptr);
}

// Scope ends here, PIDFile is deleted by its destructor
}
Expand Down
10 changes: 5 additions & 5 deletions radiantcore/Radiant.cpp
Expand Up @@ -80,17 +80,17 @@ language::ILanguageManager& Radiant::getLanguageManager()

void Radiant::startup()
{
// Register the modules hosted in this binary
module::internal::StaticModuleList::RegisterModules();

try
{
// Register the modules hosted in this binary
module::internal::StaticModuleList::RegisterModules();

module::GlobalModuleRegistry().loadAndInitialiseModules();
}
catch (const std::exception & e)
catch (const std::exception& e)
{
rConsole() << "Exception initialising modules: " << e.what() << std::endl;
abort();
throw StartupFailure(e.what()); // translate the exception
}
}

Expand Down
18 changes: 6 additions & 12 deletions radiantcore/settings/GameManager.cpp
Expand Up @@ -20,7 +20,6 @@
#include "string/split.h"
#include "string/case_conv.h"

#include "wxutil/dialog/MessageBox.h"
#include "module/StaticModule.h"
#include "messages/GameConfigNeededMessage.h"

Expand Down Expand Up @@ -137,7 +136,7 @@ IGamePtr Manager::currentGame()
if (_config.gameType.empty())
{
// No game type selected, bail out, the program will crash anyway on module load
wxutil::Messagebox::ShowFatalError(_("GameManager: No game type selected, can't continue."), nullptr);
throw std::runtime_error(_("GameManager: No game type selected, can't continue."));
}

return _games[_config.gameType];
Expand All @@ -152,11 +151,8 @@ void Manager::initialiseGameType()
{
if (_games.empty())
{
// No game types available, bail out, the program would crash anyway on
// module load
wxutil::Messagebox::ShowFatalError(
_("GameManager: No valid game files found, can't continue."), nullptr
);
// No game types available, bail out, the program would crash anyway on module load
throw std::runtime_error(_("GameManager: No valid game files found, can't continue."));
}

// Find the user's selected game from the XML registry, and attempt to find
Expand All @@ -172,9 +168,7 @@ void Manager::initialiseGameType()

if (_sortedGames.empty())
{
wxutil::Messagebox::ShowFatalError(
"GameManager: Sorted game list is empty, can't continue.", nullptr
);
throw std::runtime_error("GameManager: Sorted game list is empty, can't continue.");
}

registry::setValue(RKEY_GAME_TYPE, _sortedGames.front()->getKeyValue("name"));
Expand All @@ -191,7 +185,7 @@ void Manager::initialiseGameType()
else
{
// No game type selected, bail out, the program would crash anyway on module load
wxutil::Messagebox::ShowFatalError(_("No game type selected."));
throw std::runtime_error(_("No game type selected."));
}
}

Expand Down Expand Up @@ -257,7 +251,7 @@ void Manager::showGameSetupDialog()
}
else
{
wxutil::Messagebox::ShowFatalError(_("No valid game configuration found, cannot continue."), nullptr);
throw std::runtime_error(_("No valid game configuration found, cannot continue."));
}
}

Expand Down

0 comments on commit 57a7b05

Please sign in to comment.