mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Replace path_* error codes
path_write_fail, path_read_fail and path_not_found are replaced by the new FileAccessError exception class
This commit is contained in:
@@ -223,6 +223,7 @@ set (LOOT_HEADERS "${CMAKE_SOURCE_DIR}/src/backend/app/loot_paths.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/error_categories.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/condition_syntax_error.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/cyclic_interaction_error.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/file_access_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"
|
||||
@@ -286,6 +287,7 @@ set (LOOT_API_HEADERS "${CMAKE_SOURCE_DIR}/include/loot/api.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/error_categories.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/condition_syntax_error.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/cyclic_interaction_error.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/file_access_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"
|
||||
|
||||
@@ -55,6 +55,9 @@ Classes
|
||||
.. doxygenclass:: loot::ConditionSyntaxError
|
||||
:members:
|
||||
|
||||
.. doxygenclass:: loot::FileAccessError
|
||||
:members:
|
||||
|
||||
.. doxygenclass:: loot::Error
|
||||
:members:
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "loot/error_categories.h"
|
||||
#include "loot/exception/condition_syntax_error.h"
|
||||
#include "loot/exception/cyclic_interaction_error.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
#include "loot/exception/game_detection_error.h"
|
||||
#include "loot/exception/git_state_error.h"
|
||||
#include "loot/game_type.h"
|
||||
|
||||
@@ -46,17 +46,11 @@ public:
|
||||
* failed, but its failure was not fatal to the task being performed.
|
||||
*/
|
||||
ok = 0,
|
||||
/** An error was encountered when writing a file. */
|
||||
path_write_fail = 2,
|
||||
/** An error was encountered when reading a file. */
|
||||
path_read_fail = 3,
|
||||
/**
|
||||
* An error was encountered when attempting to evaluate a metadata
|
||||
* condition.
|
||||
*/
|
||||
condition_eval_fail = 4,
|
||||
/** A path could not be found. */
|
||||
path_not_found = 9,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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_FILE_ACCESS_ERROR
|
||||
#define LOOT_EXCEPTION_FILE_ACCESS_ERROR
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace loot {
|
||||
/**
|
||||
* @brief An exception class thrown if an error is encountered while reading or
|
||||
* writing a file.
|
||||
*/
|
||||
class FileAccessError : public std::runtime_error {
|
||||
public:
|
||||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -8,7 +8,7 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: LOOT 0.10.0\n"
|
||||
"Report-Msgid-Bugs-To: https://github.com/loot/loot/issues\n"
|
||||
"POT-Creation-Date: 2016-10-07 21:03+0100\n"
|
||||
"POT-Creation-Date: 2016-10-07 21:09+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@@ -648,15 +648,15 @@ msgstr ""
|
||||
msgid "None of the supported games were detected."
|
||||
msgstr ""
|
||||
|
||||
#: src/backend/game/game.cpp:61
|
||||
#: src/backend/game/game.cpp:62
|
||||
msgid "Invalid game ID supplied."
|
||||
msgstr ""
|
||||
|
||||
#: src/backend/game/game.cpp:68
|
||||
#: src/backend/game/game.cpp:69
|
||||
msgid "Game path could not be detected."
|
||||
msgstr ""
|
||||
|
||||
#: src/backend/game/game.cpp:78
|
||||
#: src/backend/game/game.cpp:79
|
||||
msgid "Could not create LOOT folder for game. Details:"
|
||||
msgstr ""
|
||||
|
||||
@@ -724,11 +724,11 @@ msgstr ""
|
||||
msgid "Unknown: Git repository missing"
|
||||
msgstr ""
|
||||
|
||||
#: src/backend/helpers/helpers.cpp:81
|
||||
#: src/backend/helpers/helpers.cpp:82
|
||||
msgid "Unable to open \"%1%\" for CRC calculation."
|
||||
msgstr ""
|
||||
|
||||
#: src/backend/helpers/helpers.cpp:122 src/backend/helpers/helpers.cpp:125
|
||||
#: src/backend/helpers/helpers.cpp:123 src/backend/helpers/helpers.cpp:126
|
||||
msgid "Failed to open file in its default application."
|
||||
msgstr ""
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "loot/error.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
#include "backend/game/game.h"
|
||||
#include "backend/plugin/plugin_sorter.h"
|
||||
|
||||
@@ -50,14 +51,14 @@ void ApiDatabase::LoadLists(const std::string& masterlistPath,
|
||||
if (boost::filesystem::exists(masterlistPath)) {
|
||||
temp.Load(masterlistPath);
|
||||
} else {
|
||||
throw Error(Error::Code::path_not_found, std::string("The given masterlist path does not exist: ") + masterlistPath);
|
||||
throw FileAccessError("The given masterlist path does not exist: " + masterlistPath);
|
||||
}
|
||||
|
||||
if (!userlistPath.empty()) {
|
||||
if (boost::filesystem::exists(userlistPath)) {
|
||||
userTemp.Load(userlistPath);
|
||||
} else {
|
||||
throw Error(Error::Code::path_not_found, std::string("The given userlist path does not exist: ") + userlistPath);
|
||||
throw FileAccessError("The given userlist path does not exist: " + userlistPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +220,7 @@ void ApiDatabase::WriteMinimalList(const std::string& outputFile, const bool ove
|
||||
throw std::invalid_argument("Output directory does not exist.");
|
||||
|
||||
if (boost::filesystem::exists(outputFile) && !overwrite)
|
||||
throw Error(Error::Code::path_write_fail, "Output file exists but overwrite is not set to true.");
|
||||
throw FileAccessError("Output file exists but overwrite is not set to true.");
|
||||
|
||||
Masterlist temp = game_.GetMasterlist();
|
||||
std::unordered_set<PluginMetadata> minimalPlugins;
|
||||
@@ -239,7 +240,7 @@ void ApiDatabase::WriteMinimalList(const std::string& outputFile, const bool ove
|
||||
boost::filesystem::path p(outputFile);
|
||||
boost::filesystem::ofstream out(p);
|
||||
if (out.fail())
|
||||
throw Error(Error::Code::path_write_fail, "Couldn't open output file.");
|
||||
throw FileAccessError("Couldn't open output file.");
|
||||
out << yout.c_str();
|
||||
out.close();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include "backend/app/loot_paths.h"
|
||||
#include "loot/error.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
#include "loot/exception/game_detection_error.h"
|
||||
#include "backend/helpers/helpers.h"
|
||||
|
||||
@@ -75,7 +76,7 @@ void Game::Init(bool createFolder, const boost::filesystem::path& gameLocalAppDa
|
||||
fs::create_directories(LootPaths::getLootDataPath() / FolderName());
|
||||
} catch (fs::filesystem_error& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Could not create LOOT folder for game. Details: " << e.what();
|
||||
throw Error(Error::Code::path_write_fail, translate("Could not create LOOT folder for game. Details:").str() + " " + e.what());
|
||||
throw FileAccessError(translate("Could not create LOOT folder for game. Details:").str() + " " + e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <boost/spirit/include/karma.hpp>
|
||||
|
||||
#include "loot/error.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# ifndef UNICODE
|
||||
@@ -78,7 +79,7 @@ uint32_t GetCrc32(const boost::filesystem::path& filename) {
|
||||
throw std::exception();
|
||||
} catch (std::exception&) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Unable to open \"" << filename.string() << "\" for CRC calculation.";
|
||||
throw Error(Error::Code::path_read_fail, (boost::format(translate("Unable to open \"%1%\" for CRC calculation.")) % filename.string()).str());
|
||||
throw FileAccessError((boost::format(translate("Unable to open \"%1%\" for CRC calculation.")) % filename.string()).str());
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(debug) << "CRC32(\"" << filename.string() << "\"): " << std::hex << chksum << std::dec;
|
||||
return chksum;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#include "loot/error.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
#include "backend/game/game.h"
|
||||
|
||||
namespace loot {
|
||||
@@ -39,7 +40,7 @@ void MetadataList::Load(const boost::filesystem::path& filepath) {
|
||||
|
||||
boost::filesystem::ifstream in(filepath);
|
||||
if (!in.good())
|
||||
throw Error(Error::Code::path_read_fail, "Cannot open " + filepath.string());
|
||||
throw FileAccessError("Cannot open " + filepath.string());
|
||||
|
||||
YAML::Node metadataList = YAML::Load(in);
|
||||
in.close();
|
||||
@@ -49,10 +50,8 @@ void MetadataList::Load(const boost::filesystem::path& filepath) {
|
||||
PluginMetadata plugin(node.as<PluginMetadata>());
|
||||
if (plugin.IsRegexPlugin())
|
||||
regexPlugins_.push_back(plugin);
|
||||
else {
|
||||
if (!plugins_.insert(plugin).second)
|
||||
throw Error(Error::Code::path_read_fail, "More than one entry exists for \"" + plugin.Name() + "\"");
|
||||
}
|
||||
else if (!plugins_.insert(plugin).second)
|
||||
throw FileAccessError("More than one entry exists for \"" + plugin.Name() + "\"");
|
||||
}
|
||||
}
|
||||
if (metadataList["globals"])
|
||||
|
||||
@@ -28,6 +28,7 @@ along with LOOT. If not, see
|
||||
#include "backend/helpers/helpers.h"
|
||||
|
||||
#include "loot/error.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
#include "tests/common_game_test_fixture.h"
|
||||
|
||||
namespace loot {
|
||||
@@ -44,7 +45,7 @@ INSTANTIATE_TEST_CASE_P(,
|
||||
GameType::tes5));
|
||||
|
||||
TEST_P(GetCrc32Test, gettingTheCrcOfAMissingFileShouldThrow) {
|
||||
EXPECT_THROW(GetCrc32(dataPath / missingEsp), Error);
|
||||
EXPECT_THROW(GetCrc32(dataPath / missingEsp), FileAccessError);
|
||||
}
|
||||
|
||||
TEST_P(GetCrc32Test, gettingTheCrcOfAFileShouldReturnTheCorrectValue) {
|
||||
|
||||
Reference in New Issue
Block a user