mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Remove FileAccessError
It wasn't usefully different from just throwing std::runtime_error.
This commit is contained in:
@@ -234,7 +234,6 @@ set(LIBLOOT_INCLUDE_H_FILES
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/exception/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/undefined_group_error.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/enum/edge_type.h"
|
||||
"${CMAKE_SOURCE_DIR}/include/loot/enum/game_type.h"
|
||||
|
||||
@@ -98,9 +98,6 @@ Exceptions
|
||||
.. doxygenclass:: loot::ConditionSyntaxError
|
||||
:members:
|
||||
|
||||
.. doxygenclass:: loot::FileAccessError
|
||||
:members:
|
||||
|
||||
.. doxygenclass:: loot::UndefinedGroupError
|
||||
:members:
|
||||
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include "loot/exception/condition_syntax_error.h"
|
||||
#include "loot/exception/cyclic_interaction_error.h"
|
||||
#include "loot/exception/error_categories.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
#include "loot/exception/undefined_group_error.h"
|
||||
#include "loot/game_interface.h"
|
||||
#include "loot/loot_version.h"
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/* 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
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "api/api_database.h"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
@@ -32,7 +33,6 @@
|
||||
#include "api/metadata/yaml/plugin_metadata.h"
|
||||
#include "api/sorting/group_sort.h"
|
||||
#include "api/sorting/plugin_sort.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
#include "loot/metadata/group.h"
|
||||
|
||||
namespace {
|
||||
@@ -90,7 +90,7 @@ void ApiDatabase::LoadMasterlist(const std::filesystem::path& masterlistPath) {
|
||||
if (std::filesystem::exists(masterlistPath)) {
|
||||
temp.Load(masterlistPath);
|
||||
} else {
|
||||
throw FileAccessError("The given masterlist path does not exist: " +
|
||||
throw std::runtime_error("The given masterlist path does not exist: " +
|
||||
masterlistPath.u8string());
|
||||
}
|
||||
|
||||
@@ -106,12 +106,12 @@ void ApiDatabase::LoadMasterlistWithPrelude(
|
||||
if (std::filesystem::exists(masterlistPreludePath)) {
|
||||
temp.LoadWithPrelude(masterlistPath, masterlistPreludePath);
|
||||
} else {
|
||||
throw FileAccessError(
|
||||
throw std::runtime_error(
|
||||
"The given masterlist prelude path does not exist: " +
|
||||
masterlistPreludePath.u8string());
|
||||
}
|
||||
} else {
|
||||
throw FileAccessError("The given masterlist path does not exist: " +
|
||||
throw std::runtime_error("The given masterlist path does not exist: " +
|
||||
masterlistPath.u8string());
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ void ApiDatabase::LoadUserlist(const std::filesystem::path& userlistPath) {
|
||||
if (std::filesystem::exists(userlistPath)) {
|
||||
temp.Load(userlistPath);
|
||||
} else {
|
||||
throw FileAccessError("The given userlist path does not exist: " +
|
||||
throw std::runtime_error("The given userlist path does not exist: " +
|
||||
userlistPath.u8string());
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ void ApiDatabase::WriteUserMetadata(const std::filesystem::path& outputFile,
|
||||
throw std::invalid_argument("Output directory does not exist.");
|
||||
|
||||
if (std::filesystem::exists(outputFile) && !overwrite)
|
||||
throw FileAccessError(
|
||||
throw std::runtime_error(
|
||||
"Output file exists but overwrite is not set to true.");
|
||||
|
||||
userlist_.Save(outputFile);
|
||||
@@ -274,7 +274,7 @@ void ApiDatabase::WriteMinimalList(const std::filesystem::path& outputFile,
|
||||
throw std::invalid_argument("Output directory does not exist.");
|
||||
|
||||
if (std::filesystem::exists(outputFile) && !overwrite)
|
||||
throw FileAccessError(
|
||||
throw std::runtime_error(
|
||||
"Output file exists but overwrite is not set to true.");
|
||||
|
||||
MetadataList minimalList;
|
||||
|
||||
@@ -28,12 +28,12 @@
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <cmath>
|
||||
#include <execution>
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
|
||||
#include "api/api_database.h"
|
||||
#include "api/helpers/logging.h"
|
||||
#include "api/sorting/plugin_sort.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef UNICODE
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
#include <array>
|
||||
#include <boost/crc.hpp>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "api/helpers/logging.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
|
||||
namespace loot {
|
||||
size_t GetStreamSize(std::istream& stream) {
|
||||
@@ -77,7 +77,7 @@ uint32_t GetCrc32(const std::filesystem::path& filename) {
|
||||
return checksum;
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
throw FileAccessError("Unable to open \"" + filename.u8string() +
|
||||
throw std::runtime_error("Unable to open \"" + filename.u8string() +
|
||||
"\" for CRC calulation: " + e.what());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "api/game/game.h"
|
||||
#include "api/helpers/logging.h"
|
||||
@@ -35,7 +36,6 @@
|
||||
#include "api/metadata/condition_evaluator.h"
|
||||
#include "api/metadata/yaml/group.h"
|
||||
#include "api/metadata/yaml/plugin_metadata.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
|
||||
namespace loot {
|
||||
using std::string_view_literals::operator""sv;
|
||||
@@ -46,7 +46,7 @@ constexpr std::string_view PRELUDE_ON_NEW_LINE = "\nprelude:"sv;
|
||||
std::string read_to_string(const std::filesystem::path& filePath) {
|
||||
std::ifstream in(filePath);
|
||||
if (!in.good()) {
|
||||
throw FileAccessError("Cannot open " + filePath.u8string());
|
||||
throw std::runtime_error("Cannot open " + filePath.u8string());
|
||||
}
|
||||
|
||||
auto content = std::string(std::istreambuf_iterator<char>(in),
|
||||
@@ -150,7 +150,7 @@ void MetadataList::Load(const std::filesystem::path& filepath) {
|
||||
|
||||
std::ifstream in(filepath);
|
||||
if (!in.good())
|
||||
throw FileAccessError("Cannot open " + filepath.u8string());
|
||||
throw std::runtime_error("Cannot open " + filepath.u8string());
|
||||
|
||||
this->Load(in, filepath);
|
||||
|
||||
@@ -177,7 +177,7 @@ void MetadataList::Load(std::istream& istream,
|
||||
YAML::Node metadataList = YAML::Load(istream);
|
||||
|
||||
if (!metadataList.IsMap())
|
||||
throw FileAccessError("The root of the metadata file " +
|
||||
throw std::runtime_error("The root of the metadata file " +
|
||||
source_path.u8string() + " is not a YAML map.");
|
||||
|
||||
if (metadataList["plugins"]) {
|
||||
@@ -186,7 +186,7 @@ void MetadataList::Load(std::istream& istream,
|
||||
if (plugin.IsRegexPlugin())
|
||||
regexPlugins_.push_back(plugin);
|
||||
else if (!plugins_.emplace(Filename(plugin.GetName()), plugin).second)
|
||||
throw FileAccessError("More than one entry exists for plugin \"" +
|
||||
throw std::runtime_error("More than one entry exists for plugin \"" +
|
||||
plugin.GetName() + "\"");
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ void MetadataList::Load(std::istream& istream,
|
||||
for (const auto& node : metadataList["bash_tags"]) {
|
||||
auto bashTag = node.as<std::string>();
|
||||
if (bashTags.count(bashTag) != 0) {
|
||||
throw FileAccessError("More than one entry exists for Bash Tag \"" +
|
||||
throw std::runtime_error("More than one entry exists for Bash Tag \"" +
|
||||
bashTag + "\"");
|
||||
}
|
||||
bashTags_.push_back(bashTag);
|
||||
@@ -211,7 +211,7 @@ void MetadataList::Load(std::istream& istream,
|
||||
for (const auto& node : metadataList["groups"]) {
|
||||
auto group = node.as<Group>();
|
||||
if (groupNames.count(group.GetName()) != 0) {
|
||||
throw FileAccessError("More than one entry exists for group \"" +
|
||||
throw std::runtime_error("More than one entry exists for group \"" +
|
||||
group.GetName() + "\"");
|
||||
}
|
||||
groups_.push_back(group);
|
||||
@@ -264,7 +264,7 @@ void MetadataList::Save(const std::filesystem::path& filepath) const {
|
||||
|
||||
std::ofstream out(filepath);
|
||||
if (out.fail())
|
||||
throw FileAccessError("Couldn't open output file.");
|
||||
throw std::runtime_error("Couldn't open output file.");
|
||||
|
||||
out << emitter.c_str();
|
||||
out.close();
|
||||
|
||||
+3
-3
@@ -27,6 +27,7 @@
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <filesystem>
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "api/bsa.h"
|
||||
#include "api/game/game.h"
|
||||
@@ -34,7 +35,6 @@
|
||||
#include "api/helpers/logging.h"
|
||||
#include "api/helpers/text.h"
|
||||
#include "loot/exception/error_categories.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
|
||||
namespace {
|
||||
using loot::BSA_FILE_EXTENSION;
|
||||
@@ -277,7 +277,7 @@ Plugin::Plugin(const GameType gameType,
|
||||
pluginPath.u8string(),
|
||||
e.what());
|
||||
}
|
||||
throw FileAccessError("Cannot read \"" + pluginPath.u8string() +
|
||||
throw std::runtime_error("Cannot read \"" + pluginPath.u8string() +
|
||||
"\". Details: " + e.what());
|
||||
} catch (const std::exception& e) {
|
||||
if (logger) {
|
||||
@@ -285,7 +285,7 @@ Plugin::Plugin(const GameType gameType,
|
||||
pluginPath.u8string(),
|
||||
e.what());
|
||||
}
|
||||
throw FileAccessError("Cannot read \"" + pluginPath.u8string() +
|
||||
throw std::runtime_error("Cannot read \"" + pluginPath.u8string() +
|
||||
"\". Details: " + e.what());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ TEST_P(DatabaseInterfaceTest,
|
||||
TEST_P(DatabaseInterfaceTest,
|
||||
loadMasterlistShouldThrowIfNoMasterlistIsPresent) {
|
||||
EXPECT_THROW(handle_->GetDatabase().LoadMasterlist(masterlistPath),
|
||||
FileAccessError);
|
||||
std::runtime_error);
|
||||
}
|
||||
|
||||
TEST_P(DatabaseInterfaceTest,
|
||||
@@ -146,7 +146,7 @@ TEST_P(
|
||||
|
||||
EXPECT_THROW(handle_->GetDatabase().LoadMasterlistWithPrelude(masterlistPath,
|
||||
preludePath),
|
||||
FileAccessError);
|
||||
std::runtime_error);
|
||||
}
|
||||
|
||||
TEST_P(
|
||||
@@ -185,7 +185,7 @@ TEST_P(DatabaseInterfaceTest,
|
||||
loadUserlistShouldThrowIfAUserlistDoesNotExistAtTheGivenPath) {
|
||||
ASSERT_NO_THROW(GenerateMasterlist());
|
||||
EXPECT_THROW(handle_->GetDatabase().LoadUserlist(userlistPath_),
|
||||
FileAccessError);
|
||||
std::runtime_error);
|
||||
}
|
||||
|
||||
TEST_P(DatabaseInterfaceTest, loadUserlistShouldSucceedIfTheUserlistIsPresent) {
|
||||
@@ -204,7 +204,7 @@ TEST_P(
|
||||
|
||||
EXPECT_THROW(
|
||||
handle_->GetDatabase().WriteUserMetadata(minimalOutputPath_, false),
|
||||
FileAccessError);
|
||||
std::runtime_error);
|
||||
}
|
||||
|
||||
TEST_P(
|
||||
@@ -238,7 +238,7 @@ TEST_P(DatabaseInterfaceTest,
|
||||
|
||||
EXPECT_THROW(
|
||||
handle_->GetDatabase().WriteUserMetadata(minimalOutputPath_, true),
|
||||
FileAccessError);
|
||||
std::runtime_error);
|
||||
}
|
||||
|
||||
TEST_P(DatabaseInterfaceTest,
|
||||
@@ -753,7 +753,7 @@ TEST_P(
|
||||
|
||||
EXPECT_THROW(
|
||||
handle_->GetDatabase().WriteMinimalList(minimalOutputPath_, false),
|
||||
FileAccessError);
|
||||
std::runtime_error);
|
||||
}
|
||||
|
||||
TEST_P(
|
||||
@@ -787,7 +787,7 @@ TEST_P(DatabaseInterfaceTest,
|
||||
|
||||
EXPECT_THROW(
|
||||
handle_->GetDatabase().WriteMinimalList(minimalOutputPath_, true),
|
||||
FileAccessError);
|
||||
std::runtime_error);
|
||||
}
|
||||
|
||||
TEST_P(DatabaseInterfaceTest,
|
||||
|
||||
@@ -25,8 +25,9 @@ along with LOOT. If not, see
|
||||
#ifndef LOOT_TESTS_API_INTERNALS_HELPERS_CRC_TEST
|
||||
#define LOOT_TESTS_API_INTERNALS_HELPERS_CRC_TEST
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "api/helpers/crc.h"
|
||||
#include "loot/exception/file_access_error.h"
|
||||
#include "tests/common_game_test_fixture.h"
|
||||
|
||||
namespace loot {
|
||||
@@ -37,7 +38,7 @@ protected:
|
||||
};
|
||||
|
||||
TEST_F(GetCrc32Test, gettingTheCrcOfAMissingFileShouldThrow) {
|
||||
EXPECT_THROW(GetCrc32(dataPath / missingEsp), FileAccessError);
|
||||
EXPECT_THROW(GetCrc32(dataPath / missingEsp), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST_F(GetCrc32Test, gettingTheCrcOfAFileShouldReturnTheCorrectValue) {
|
||||
|
||||
@@ -208,7 +208,7 @@ plugins:
|
||||
- 'Blank.esm')";
|
||||
out.close();
|
||||
|
||||
EXPECT_THROW(metadataList.Load(metadataPath), FileAccessError);
|
||||
EXPECT_THROW(metadataList.Load(metadataPath), std::runtime_error);
|
||||
|
||||
out.open(metadataPath);
|
||||
out << R"(globals:
|
||||
@@ -231,7 +231,7 @@ plugins:
|
||||
content: 'This plugin entry will cause a failure, as it is not the first exact entry.')";
|
||||
out.close();
|
||||
|
||||
EXPECT_THROW(metadataList.Load(metadataPath), FileAccessError);
|
||||
EXPECT_THROW(metadataList.Load(metadataPath), std::runtime_error);
|
||||
}
|
||||
|
||||
TEST_F(MetadataListTest,
|
||||
@@ -243,7 +243,7 @@ TEST_F(MetadataListTest,
|
||||
ASSERT_FALSE(metadataList.Plugins().empty());
|
||||
ASSERT_FALSE(metadataList.BashTags().empty());
|
||||
|
||||
EXPECT_THROW(metadataList.Load(blankEsm), FileAccessError);
|
||||
EXPECT_THROW(metadataList.Load(blankEsm), std::runtime_error);
|
||||
EXPECT_TRUE(metadataList.Messages().empty());
|
||||
EXPECT_TRUE(metadataList.Plugins().empty());
|
||||
EXPECT_TRUE(metadataList.BashTags().empty());
|
||||
@@ -258,7 +258,7 @@ TEST_F(MetadataListTest,
|
||||
ASSERT_FALSE(metadataList.Plugins().empty());
|
||||
ASSERT_FALSE(metadataList.BashTags().empty());
|
||||
|
||||
EXPECT_THROW(metadataList.Load(missingMetadataPath), FileAccessError);
|
||||
EXPECT_THROW(metadataList.Load(missingMetadataPath), std::runtime_error);
|
||||
EXPECT_TRUE(metadataList.Messages().empty());
|
||||
EXPECT_TRUE(metadataList.Plugins().empty());
|
||||
EXPECT_TRUE(metadataList.BashTags().empty());
|
||||
|
||||
Reference in New Issue
Block a user