Browse Source

Better error message on missing object constructor

Ivan Savenko 2 năm trước cách đây
mục cha
commit
2e7e8bb52b
1 tập tin đã thay đổi với 14 bổ sung4 xóa
  1. 14 4
      lib/mapObjectConstructors/CObjectClassesHandler.cpp

+ 14 - 4
lib/mapObjectConstructors/CObjectClassesHandler.cpp

@@ -316,11 +316,21 @@ std::vector<bool> CObjectClassesHandler::getDefaultAllowed() const
 
 TObjectTypeHandler CObjectClassesHandler::getHandlerFor(si32 type, si32 subtype) const
 {
-	assert(type < objects.size());
-	assert(objects[type]);
-	assert(subtype < objects[type]->objects.size());
+	try
+	{
+		auto result = objects.at(type)->objects.at(subtype);
+
+		if (result != nullptr)
+			return result;
+	}
+	catch (std::out_of_range & e)
+	{
+		// Leave catch block silently
+	}
 
-	return objects.at(type)->objects.at(subtype);
+	std::string errorString = "Failed to find object of type " + std::to_string(type) + "::" + std::to_string(subtype);
+	logGlobal->error(errorString);
+	throw std::runtime_error(errorString);
 }
 
 TObjectTypeHandler CObjectClassesHandler::getHandlerFor(const std::string & scope, const std::string & type, const std::string & subtype) const