diff --git a/SPID/include/FormData.h b/SPID/include/FormData.h index 3d46c05..aef1856 100644 --- a/SPID/include/FormData.h +++ b/SPID/include/FormData.h @@ -37,13 +37,13 @@ namespace Forms /// struct MismatchingFormTypeException : std::exception { - const RE::FormType expectedFformType; + const RE::FormType expectedFormType; const RE::FormType actualFormType; const FormOrEditorID formOrEditorID; const std::string path; - MismatchingFormTypeException(RE::FormType expectedFformType, RE::FormType actualFormType, const FormOrEditorID& formOrEditorID, const std::string& path) : - expectedFformType(expectedFformType), + MismatchingFormTypeException(RE::FormType expectedFormType, RE::FormType actualFormType, const FormOrEditorID& formOrEditorID, const std::string& path) : + expectedFormType(expectedFormType), actualFormType(actualFormType), formOrEditorID(formOrEditorID), path(path) @@ -216,8 +216,10 @@ namespace Forms } form = as_form(anyForm); - if (!form) { - throw MismatchingFormTypeException(anyForm->GetFormType(), Form::FORMTYPE, FormModPair{ *formID, modName }, path); + if (!form || anyForm->GetFormType() != Form::FORMTYPE) { + // Ideally, we'd want to throw separate exception for unsupported form type, + // so that attempting to distribute, for example, CELL would properly report such error. + throw MismatchingFormTypeException(Form::FORMTYPE, anyForm->GetFormType(), FormModPair{ *formID, modName }, path); } if constexpr (std::is_same_v) { @@ -232,7 +234,6 @@ namespace Forms if (editorID.empty()) { throw MalformedEditorIDException(path); } - // if constexpr (std::is_same_v) { form = find_or_create_keyword(editorID); } else { @@ -322,10 +323,10 @@ namespace Forms std::visit(overload{ [&](const FormModPair& formMod) { auto& [formID, modName] = formMod; - buffered_logger::error("\t\t[{}] Filter[0x{:X}] ({}) FAIL - mismatching form type (expected: {}, actual: {})", e.path, *formID, modName.value_or(""), RE::FormTypeToString(e.expectedFformType), RE::FormTypeToString(e.actualFormType)); + buffered_logger::error("\t\t[{}] Filter[0x{:X}] ({}) FAIL - mismatching form type (expected: {}, actual: {})", e.path, *formID, modName.value_or(""), RE::FormTypeToString(e.expectedFormType), RE::FormTypeToString(e.actualFormType)); }, [&](std::string editorID) { - buffered_logger::error("\t\t[{}] Filter ({}) FAIL - mismatching form type (expected: {}, actual: {})", e.path, editorID, RE::FormTypeToString(e.expectedFformType), RE::FormTypeToString(e.actualFormType)); + buffered_logger::error("\t\t[{}] Filter ({}) FAIL - mismatching form type (expected: {}, actual: {})", e.path, editorID, RE::FormTypeToString(e.expectedFormType), RE::FormTypeToString(e.actualFormType)); } }, e.formOrEditorID); } catch (const InvalidFormTypeException& e) { @@ -631,10 +632,10 @@ void Forms::LookupGenericForm(RE::TESDataHandler* const dataHandler, INI::Data& std::visit(overload{ [&](const FormModPair& formMod) { auto& [formID, modName] = formMod; - buffered_logger::error("\t\t[{}] [0x{:X}] ({}) FAIL - mismatching form type (expected: {}, actual: {})", e.path, *formID, modName.value_or(""), RE::FormTypeToString(e.expectedFformType), RE::FormTypeToString(e.actualFormType)); + buffered_logger::error("\t\t[{}] [0x{:X}] ({}) FAIL - mismatching form type (expected: {}, actual: {})", e.path, *formID, modName.value_or(""), RE::FormTypeToString(e.expectedFormType), RE::FormTypeToString(e.actualFormType)); }, [&](std::string editorID) { - buffered_logger::error("\t\t[{}] ({}) FAIL - mismatching form type (expected: {}, actual: {})", e.path, editorID, RE::FormTypeToString(e.expectedFformType), RE::FormTypeToString(e.actualFormType)); + buffered_logger::error("\t\t[{}] ({}) FAIL - mismatching form type (expected: {}, actual: {})", e.path, editorID, RE::FormTypeToString(e.expectedFormType), RE::FormTypeToString(e.actualFormType)); } }, e.formOrEditorID); } catch (const Lookup::InvalidFormTypeException& e) { diff --git a/SPID/include/LinkedDistribution.h b/SPID/include/LinkedDistribution.h index 537b1fd..f85bf1a 100644 --- a/SPID/include/LinkedDistribution.h +++ b/SPID/include/LinkedDistribution.h @@ -153,10 +153,10 @@ namespace LinkedDistribution std::visit(overload{ [&](const FormModPair& formMod) { auto& [formID, modName] = formMod; - buffered_logger::error("\t\t[{}] LinkedForm [0x{:X}] ({}) SKIP - mismatching form type (expected: {}, actual: {})", e.path, *formID, modName.value_or(""), RE::FormTypeToString(e.expectedFformType), RE::FormTypeToString(e.actualFormType)); + buffered_logger::error("\t\t[{}] LinkedForm [0x{:X}] ({}) SKIP - mismatching form type (expected: {}, actual: {})", e.path, *formID, modName.value_or(""), RE::FormTypeToString(e.expectedFormType), RE::FormTypeToString(e.actualFormType)); }, [&](std::string editorID) { - buffered_logger::error("\t\t[{}] LinkedForm ({}) SKIP - mismatching form type (expected: {}, actual: {})", e.path, editorID, RE::FormTypeToString(e.expectedFformType), RE::FormTypeToString(e.actualFormType)); + buffered_logger::error("\t\t[{}] LinkedForm ({}) SKIP - mismatching form type (expected: {}, actual: {})", e.path, editorID, RE::FormTypeToString(e.expectedFormType), RE::FormTypeToString(e.actualFormType)); } }, e.formOrEditorID); } catch (const InvalidFormTypeException& e) { diff --git a/SPID/include/LookupConfigs.h b/SPID/include/LookupConfigs.h index d4c10fe..79f994c 100644 --- a/SPID/include/LookupConfigs.h +++ b/SPID/include/LookupConfigs.h @@ -27,7 +27,7 @@ namespace RECORD namespace detail { - inline static constexpr std::array add{ + inline static constexpr std::array names{ "Form"sv, "Spell"sv, "Perk"sv, @@ -46,25 +46,14 @@ namespace RECORD inline constexpr std::string_view GetTypeName(const TYPE aType) { - return detail::add.at(aType); + return detail::names.at(aType); } - inline constexpr TYPE GetType(const std::string& aType) + template + constexpr TYPE GetType(const T& aType) { using namespace detail; - return static_cast(std::distance(add.begin(), std::find(add.begin(), add.end(), aType))); - } - - inline constexpr TYPE GetType(const std::string_view& aType) - { - using namespace detail; - return static_cast(std::distance(add.begin(), std::find(add.begin(), add.end(), aType))); - } - - inline constexpr TYPE GetType(const char* aType) - { - using namespace detail; - return static_cast(std::distance(add.begin(), std::find(add.begin(), add.end(), aType))); + return static_cast(std::distance(names.begin(), std::find(names.begin(), names.end(), aType))); } } diff --git a/SPID/src/LinkedDistribution.cpp b/SPID/src/LinkedDistribution.cpp index b0b7886..b5c849a 100644 --- a/SPID/src/LinkedDistribution.cpp +++ b/SPID/src/LinkedDistribution.cpp @@ -30,7 +30,7 @@ namespace LinkedDistribution std::string rawType = a_key.substr(6); auto type = RECORD::GetType(rawType); if (type == RECORD::kTotal) { - logger::warn("IGNORED: Invalid Linked Form type: {}"sv, rawType); + logger::warn("IGNORED: Unsupported Linked Form type: {}"sv, rawType); return true; } @@ -136,13 +136,15 @@ namespace LinkedDistribution if (std::holds_alternative(idxOrCount)) { auto& count = std::get(idxOrCount); if (!count.IsExact()) { - logger::warn("Inferred Form is a Package, but specifies a random count instead of index. Min value ({}) of the range will be used as an index.", count.min); + logger::warn("\t[{}] Inferred Form is a Package, but specifies a random count instead of index. Min value ({}) of the range will be used as an index.", path, count.min); } packageIndex = count.min; } else { packageIndex = std::get(idxOrCount); } packages.Link(form, parentForms, packageIndex, chance, path); + } else { + logger::warn("\t[{}] Unsupported Form type: {}", path, RE::FormTypeToString(type)); } } } diff --git a/SPID/src/LookupConfigs.cpp b/SPID/src/LookupConfigs.cpp index 8d4f869..88cbe95 100644 --- a/SPID/src/LookupConfigs.cpp +++ b/SPID/src/LookupConfigs.cpp @@ -327,6 +327,10 @@ namespace INI } auto type = RECORD::GetType(key.pItem); + if (type == RECORD::kTotal) { + logger::warn("\t\tUnsupported Form type: {}"sv, key.pItem); + continue; + } auto [data, sanitized_str] = detail::parse_ini(type, entry, truncatedPath); configs[type].emplace_back(data); @@ -335,7 +339,7 @@ namespace INI oldFormatMap.emplace(key, std::make_pair(entry, *sanitized_str)); } } catch (...) { - logger::warn("\t\tFailed to parse entry [{} = {}]", key.pItem, entry); + logger::warn("\t\tFailed to parse entry [{} = {}]"sv, key.pItem, entry); shouldLogErrors = true; } } diff --git a/SPID/src/LookupForms.cpp b/SPID/src/LookupForms.cpp index bf64d33..996e5e3 100644 --- a/SPID/src/LookupForms.cpp +++ b/SPID/src/LookupForms.cpp @@ -43,13 +43,15 @@ bool LookupDistributables(RE::TESDataHandler* const dataHandler) if (std::holds_alternative(idxOrCount)) { auto& count = std::get(idxOrCount); if (!count.IsExact()) { - logger::warn("Inferred Form is a Package, but specifies a random count instead of index. Min value ({}) of the range will be used as an index.", count.min); + logger::warn("\t[{}] Inferred Form is a Package, but specifies a random count instead of index. Min value ({}) of the range will be used as an index.", path, count.min); } packageIndex = count.min; } else { packageIndex = std::get(idxOrCount); } packages.EmplaceForm(isValid, form, packageIndex, filters, path); + } else { + logger::warn("\t[{}] Unsupported Form type: {}", path, RE::FormTypeToString(type)); } } });