Replace no_game_detected error code

With a new GameDetectionError exception class.
This commit is contained in:
Oliver Hamlet
2016-10-08 12:21:07 +01:00
parent 2d28e04b36
commit a9ddd12e80
8 changed files with 60 additions and 15 deletions
+2
View File
@@ -222,6 +222,7 @@ set (LOOT_HEADERS "${CMAKE_SOURCE_DIR}/src/backend/app/loot_paths.h"
"${CMAKE_SOURCE_DIR}/include/loot/error.h"
"${CMAKE_SOURCE_DIR}/include/loot/error_categories.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/cyclic_interaction_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/game_detection_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/git_state_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/game_type.h"
"${CMAKE_SOURCE_DIR}/include/loot/language_code.h"
@@ -283,6 +284,7 @@ set (LOOT_API_HEADERS "${CMAKE_SOURCE_DIR}/include/loot/api.h"
"${CMAKE_SOURCE_DIR}/include/loot/error.h"
"${CMAKE_SOURCE_DIR}/include/loot/error_categories.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/cyclic_interaction_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/game_detection_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/exception/git_state_error.h"
"${CMAKE_SOURCE_DIR}/include/loot/game_type.h"
"${CMAKE_SOURCE_DIR}/include/loot/language_code.h"
+3
View File
@@ -49,6 +49,9 @@ Classes
.. doxygenclass:: loot::GitStateError
:members:
.. doxygenclass:: loot::GameDetectionError
:members:
.. doxygenclass:: loot::Error
:members:
+1
View File
@@ -33,6 +33,7 @@
#include "loot/error.h"
#include "loot/error_categories.h"
#include "loot/exception/cyclic_interaction_error.h"
#include "loot/exception/game_detection_error.h"
#include "loot/exception/git_state_error.h"
#include "loot/game_type.h"
#include "loot/loot_version.h"
-2
View File
@@ -57,8 +57,6 @@ public:
condition_eval_fail = 4,
/** A path could not be found. */
path_not_found = 9,
/** None of LOOT's supported games could be detected. */
no_game_detected = 10,
};
/**
@@ -0,0 +1,41 @@
/* LOOT
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
Fallout: New Vegas.
Copyright (C) 2012-2016 WrinklyNinja
This file is part of LOOT.
LOOT is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
LOOT is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LOOT. If not, see
<https://www.gnu.org/licenses/>.
*/
#ifndef LOOT_EXCEPTION_GAME_DETECTION_ERROR
#define LOOT_EXCEPTION_GAME_DETECTION_ERROR
#include <stdexcept>
namespace loot {
/**
* @brief An exception class thrown if an error occurs when detecting installed
* games.
*/
class GameDetectionError : public std::runtime_error {
public:
using std::runtime_error::runtime_error;
};
}
#endif
+6 -7
View File
@@ -35,6 +35,7 @@
#include <boost/log/utility/setup/file.hpp>
#include "loot/error.h"
#include "loot/exception/game_detection_error.h"
#include "backend/app/loot_paths.h"
#include "backend/helpers/helpers.h"
#include "backend/helpers/language.h"
@@ -186,13 +187,11 @@ void LootState::init(const std::string& cmdLineGame) {
currentGame_->Init(true);
// Update game path in settings object.
storeGameSettings(toGameSettings(games_));
} catch (GameDetectionError& e) {
initErrors_.push_back(e.what());
} catch (Error &e) {
if (e.code() == Error::Code::no_game_detected) {
initErrors_.push_back(e.what());
} else {
BOOST_LOG_TRIVIAL(error) << "Game-specific settings could not be initialised. " << e.what();
initErrors_.push_back((format(translate("Error: Game-specific settings could not be initialised. %1%")) % e.what()).str());
}
BOOST_LOG_TRIVIAL(error) << "Game-specific settings could not be initialised. " << e.what();
initErrors_.push_back((format(translate("Error: Game-specific settings could not be initialised. %1%")) % e.what()).str());
}
BOOST_LOG_TRIVIAL(debug) << "Game selected is " << currentGame_->Name();
}
@@ -271,7 +270,7 @@ void LootState::selectGame(std::string preferredGame) {
// If no game can be selected, throw an exception.
if (currentGame_ == end(games_)) {
BOOST_LOG_TRIVIAL(error) << "None of the supported games were detected.";
throw Error(Error::Code::no_game_detected, translate("None of the supported games were detected."));
throw GameDetectionError(translate("None of the supported games were detected."));
}
}
+2 -1
View File
@@ -33,6 +33,7 @@
#include "backend/app/loot_paths.h"
#include "loot/error.h"
#include "loot/exception/game_detection_error.h"
#include "backend/helpers/helpers.h"
using boost::locale::translate;
@@ -64,7 +65,7 @@ void Game::Init(bool createFolder, const boost::filesystem::path& gameLocalAppDa
if (!this->IsInstalled()) {
BOOST_LOG_TRIVIAL(error) << "Game path could not be detected.";
throw Error(Error::Code::path_not_found, translate("Game path could not be detected.").str());
throw GameDetectionError(translate("Game path could not be detected."));
}
if (createFolder) {
+5 -5
View File
@@ -28,7 +28,7 @@ along with LOOT. If not, see
#include "backend/game/game.h"
#include "backend/app/loot_paths.h"
#include "loot/error.h"
#include "loot/exception/game_detection_error.h"
#include "tests/backend/game/load_order_handler_test.h"
namespace loot {
@@ -89,10 +89,10 @@ TEST_P(GameTest, constructingFromIdAndFolderShouldPassThemToGameSettingsConstruc
// test autodetection fully unless on Linux.
TEST_P(GameTest, initShouldThrowOnLinuxIfGamePathIsNotGiven) {
Game game = Game(GetParam());
EXPECT_THROW(game.Init(false), Error);
EXPECT_THROW(game.Init(true), Error);
EXPECT_THROW(game.Init(false, localPath), Error);
EXPECT_THROW(game.Init(true, localPath), Error);
EXPECT_THROW(game.Init(false), GameDetectionError);
EXPECT_THROW(game.Init(true), GameDetectionError);
EXPECT_THROW(game.Init(false, localPath), GameDetectionError);
EXPECT_THROW(game.Init(true, localPath), GameDetectionError);
}
TEST_P(GameTest, initShouldThrowOnLinuxIfLocalPathIsNotGiven) {