From dc8dfe81cea837ac3cd37566c59049723fe26cd6 Mon Sep 17 00:00:00 2001 From: elsid Date: Thu, 25 May 2023 20:44:10 +0200 Subject: [PATCH] Add more details to exceptions --- apps/opencs/model/world/collection.hpp | 11 ++++++----- apps/opencs/model/world/metadata.hpp | 2 ++ apps/opencs/model/world/refidcollection.cpp | 2 +- components/esm3/cellref.hpp | 2 ++ components/esm3/debugprofile.hpp | 2 ++ components/esm3/filter.hpp | 2 ++ 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/opencs/model/world/collection.hpp b/apps/opencs/model/world/collection.hpp index d1b20bdedd..889d528a50 100644 --- a/apps/opencs/model/world/collection.hpp +++ b/apps/opencs/model/world/collection.hpp @@ -296,9 +296,8 @@ namespace CSMWorld const int index = getIndex(id); Record& record = *mRecords.at(index); if (record.isDeleted()) - { - throw std::runtime_error("attempt to touch deleted record"); - } + throw std::runtime_error("attempt to touch deleted record from collection of " + + std::string(ESXRecordT::getRecordType()) + ": " + id.toDebugString()); if (!record.isModified()) { @@ -394,7 +393,8 @@ namespace CSMWorld int index = searchId(id); if (index == -1) - throw std::runtime_error("invalid ID: " + id.getRefIdString()); + throw std::runtime_error("ID is not found in collection of " + std::string(ESXRecordT::getRecordType()) + + " records: " + id.getRefIdString()); return index; } @@ -427,7 +427,8 @@ namespace CSMWorld NestableColumn* Collection::getNestableColumn(int column) const { if (column < 0 || column >= static_cast(mColumns.size())) - throw std::runtime_error("column index out of range"); + throw std::runtime_error( + "column index out of range [0, " + std::to_string(mColumns.size()) + "): " + std::to_string(column)); return mColumns.at(column); } diff --git a/apps/opencs/model/world/metadata.hpp b/apps/opencs/model/world/metadata.hpp index 5d892508af..963ca6453d 100644 --- a/apps/opencs/model/world/metadata.hpp +++ b/apps/opencs/model/world/metadata.hpp @@ -16,6 +16,8 @@ namespace CSMWorld { struct MetaData { + static constexpr std::string_view getRecordType() { return "MetaData"; } + ESM::RefId mId; ESM::FormatVersion mFormatVersion; diff --git a/apps/opencs/model/world/refidcollection.cpp b/apps/opencs/model/world/refidcollection.cpp index 863114a9cc..668ee810ee 100644 --- a/apps/opencs/model/world/refidcollection.cpp +++ b/apps/opencs/model/world/refidcollection.cpp @@ -658,7 +658,7 @@ int CSMWorld::RefIdCollection::getIndex(const ESM::RefId& id) const int index = searchId(id); if (index == -1) - throw std::runtime_error("invalid ID: " + id.toDebugString()); + throw std::runtime_error("ID is not found in RefId collection: " + id.toDebugString()); return index; } diff --git a/components/esm3/cellref.hpp b/components/esm3/cellref.hpp index 8a5416d674..fe17c66ee1 100644 --- a/components/esm3/cellref.hpp +++ b/components/esm3/cellref.hpp @@ -27,6 +27,8 @@ namespace ESM class CellRef { public: + static constexpr std::string_view getRecordType() { return "CellRef"; } + // Reference number // Note: Currently unused for items in containers RefNum mRefNum; diff --git a/components/esm3/debugprofile.hpp b/components/esm3/debugprofile.hpp index 9f13598ce0..fc48fb23f6 100644 --- a/components/esm3/debugprofile.hpp +++ b/components/esm3/debugprofile.hpp @@ -15,6 +15,8 @@ namespace ESM { constexpr static RecNameInts sRecordId = REC_DBGP; + static constexpr std::string_view getRecordType() { return "DebugProfile"; } + enum Flags { Flag_Default = 1, // add to newly opened scene subviews diff --git a/components/esm3/filter.hpp b/components/esm3/filter.hpp index f340d046d1..c4642285af 100644 --- a/components/esm3/filter.hpp +++ b/components/esm3/filter.hpp @@ -15,6 +15,8 @@ namespace ESM { constexpr static RecNameInts sRecordId = REC_FILT; + static constexpr std::string_view getRecordType() { return "Filter"; } + unsigned int mRecordFlags; RefId mId;