From 98234cc9cc5c1cadb4c51232f7fdf83ca9add9a4 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Thu, 15 May 2025 17:37:13 +0100 Subject: [PATCH] Remove FileAccessError It wasn't usefully different from just throwing std::runtime_error. --- CMakeLists.txt | 1 - docs/api/reference.rst | 3 -- include/loot/api.h | 1 - include/loot/exception/file_access_error.h | 41 ------------------- src/api/api_database.cpp | 14 +++---- src/api/game/game.cpp | 2 +- src/api/helpers/crc.cpp | 4 +- src/api/metadata_list.cpp | 16 ++++---- src/api/plugin.cpp | 6 +-- .../api/interface/database_interface_test.h | 14 +++---- src/tests/api/internals/helpers/crc_test.h | 5 ++- src/tests/api/internals/metadata_list_test.h | 8 ++-- 12 files changed, 35 insertions(+), 80 deletions(-) delete mode 100644 include/loot/exception/file_access_error.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 674bbcda..b3b52a6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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" diff --git a/docs/api/reference.rst b/docs/api/reference.rst index 28127bd7..5f32dd42 100644 --- a/docs/api/reference.rst +++ b/docs/api/reference.rst @@ -98,9 +98,6 @@ Exceptions .. doxygenclass:: loot::ConditionSyntaxError :members: -.. doxygenclass:: loot::FileAccessError - :members: - .. doxygenclass:: loot::UndefinedGroupError :members: diff --git a/include/loot/api.h b/include/loot/api.h index 7dc458a7..bdf79f33 100644 --- a/include/loot/api.h +++ b/include/loot/api.h @@ -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" diff --git a/include/loot/exception/file_access_error.h b/include/loot/exception/file_access_error.h deleted file mode 100644 index af4ab237..00000000 --- a/include/loot/exception/file_access_error.h +++ /dev/null @@ -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 - . - */ - -#ifndef LOOT_EXCEPTION_FILE_ACCESS_ERROR -#define LOOT_EXCEPTION_FILE_ACCESS_ERROR - -#include - -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 diff --git a/src/api/api_database.cpp b/src/api/api_database.cpp index c19d2f5f..2eff574a 100644 --- a/src/api/api_database.cpp +++ b/src/api/api_database.cpp @@ -24,6 +24,7 @@ #include "api/api_database.h" +#include #include #include @@ -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; diff --git a/src/api/game/game.cpp b/src/api/game/game.cpp index b36337c2..65791016 100644 --- a/src/api/game/game.cpp +++ b/src/api/game/game.cpp @@ -28,12 +28,12 @@ #include #include #include +#include #include #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 diff --git a/src/api/helpers/crc.cpp b/src/api/helpers/crc.cpp index 10173807..6aad89ac 100644 --- a/src/api/helpers/crc.cpp +++ b/src/api/helpers/crc.cpp @@ -29,9 +29,9 @@ #include #include #include +#include #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()); } } diff --git a/src/api/metadata_list.cpp b/src/api/metadata_list.cpp index c253b436..16fbf35a 100644 --- a/src/api/metadata_list.cpp +++ b/src/api/metadata_list.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #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(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(); 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(); 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(); diff --git a/src/api/plugin.cpp b/src/api/plugin.cpp index 3428df24..48056dd2 100644 --- a/src/api/plugin.cpp +++ b/src/api/plugin.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #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()); } } diff --git a/src/tests/api/interface/database_interface_test.h b/src/tests/api/interface/database_interface_test.h index 35a7af9d..7e7a1421 100644 --- a/src/tests/api/interface/database_interface_test.h +++ b/src/tests/api/interface/database_interface_test.h @@ -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, diff --git a/src/tests/api/internals/helpers/crc_test.h b/src/tests/api/internals/helpers/crc_test.h index a3ee8d18..e16c7434 100644 --- a/src/tests/api/internals/helpers/crc_test.h +++ b/src/tests/api/internals/helpers/crc_test.h @@ -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 + #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) { diff --git a/src/tests/api/internals/metadata_list_test.h b/src/tests/api/internals/metadata_list_test.h index ea618dde..77d604d4 100644 --- a/src/tests/api/internals/metadata_list_test.h +++ b/src/tests/api/internals/metadata_list_test.h @@ -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());