mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Merge pull request #2403 from IvanSavenko/error_detection_fix
Attempt to fix & improve error reporting
This commit is contained in:
		
							
								
								
									
										20
									
								
								Global.h
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								Global.h
									
									
									
									
									
								
							| @@ -253,26 +253,6 @@ using TLockGuardRec = std::lock_guard<std::recursive_mutex>; | |||||||
|  |  | ||||||
| VCMI_LIB_NAMESPACE_BEGIN | VCMI_LIB_NAMESPACE_BEGIN | ||||||
|  |  | ||||||
| void inline handleException() |  | ||||||
| { |  | ||||||
| 	try |  | ||||||
| 	{ |  | ||||||
| 		throw; |  | ||||||
| 	} |  | ||||||
| 	catch(const std::exception & ex) |  | ||||||
| 	{ |  | ||||||
| 		logGlobal->error(ex.what()); |  | ||||||
| 	} |  | ||||||
| 	catch(const std::string & ex) |  | ||||||
| 	{ |  | ||||||
| 		logGlobal->error(ex); |  | ||||||
| 	} |  | ||||||
| 	catch(...) |  | ||||||
| 	{ |  | ||||||
| 		logGlobal->error("Sorry, caught unknown exception type. No more info available."); |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|  |  | ||||||
| namespace vstd | namespace vstd | ||||||
| { | { | ||||||
| 	// combine hashes. Present in boost but not in std | 	// combine hashes. Present in boost but not in std | ||||||
|   | |||||||
| @@ -865,8 +865,11 @@ void CServerHandler::threadHandleConnection() | |||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| 		{ | 		{ | ||||||
| 			logNetwork->error("Lost connection to server, ending listening thread!"); | 			if (e.code() == boost::asio::error::eof) | ||||||
| 			logNetwork->error(e.what()); | 				logNetwork->error("Lost connection to server, ending listening thread! Connection has been closed"); | ||||||
|  | 			else | ||||||
|  | 				logNetwork->error("Lost connection to server, ending listening thread! Reason: %s", e.what()); | ||||||
|  |  | ||||||
| 			if(client) | 			if(client) | ||||||
| 			{ | 			{ | ||||||
| 				state = EClientState::DISCONNECTING; | 				state = EClientState::DISCONNECTING; | ||||||
|   | |||||||
| @@ -48,17 +48,10 @@ DLL_LINKAGE void preinitDLL(CConsoleHandler * Console, bool onlyEssential, bool | |||||||
| { | { | ||||||
| 	console = Console; | 	console = Console; | ||||||
| 	VLC = new LibClasses(); | 	VLC = new LibClasses(); | ||||||
| 	try |  | ||||||
| 	{ |  | ||||||
| 	VLC->loadFilesystem(extractArchives); | 	VLC->loadFilesystem(extractArchives); | ||||||
| 	settings.init(); | 	settings.init(); | ||||||
| 	VLC->loadModFilesystem(onlyEssential); | 	VLC->loadModFilesystem(onlyEssential); | ||||||
| 	} |  | ||||||
| 	catch(...) |  | ||||||
| 	{ |  | ||||||
| 		handleException(); |  | ||||||
| 		throw; |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
|  |  | ||||||
| DLL_LINKAGE void loadDLLClasses(bool onlyEssential) | DLL_LINKAGE void loadDLLClasses(bool onlyEssential) | ||||||
|   | |||||||
| @@ -569,7 +569,6 @@ void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRan | |||||||
| 			catch(...) | 			catch(...) | ||||||
| 			{ | 			{ | ||||||
| 				logGlobal->error("Saving random map failed with exception"); | 				logGlobal->error("Saving random map failed with exception"); | ||||||
| 				handleException(); |  | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -220,7 +220,7 @@ public: | |||||||
| 	void write(const LogRecord & record) override; | 	void write(const LogRecord & record) override; | ||||||
|  |  | ||||||
| private: | private: | ||||||
| 	FileStream file; | 	boost::filesystem::fstream file; | ||||||
| 	CLogFormatter formatter; | 	CLogFormatter formatter; | ||||||
| 	mutable std::mutex mx; | 	mutable std::mutex mx; | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -77,16 +77,9 @@ void AObjectTypeHandler::init(const JsonNode & input) | |||||||
| 		tmpl->id = Obj(type); | 		tmpl->id = Obj(type); | ||||||
| 		tmpl->subid = subtype; | 		tmpl->subid = subtype; | ||||||
| 		tmpl->stringID = entry.first; // FIXME: create "fullID" - type.object.template? | 		tmpl->stringID = entry.first; // FIXME: create "fullID" - type.object.template? | ||||||
| 		try |  | ||||||
| 		{ |  | ||||||
| 		tmpl->readJson(entry.second); | 		tmpl->readJson(entry.second); | ||||||
| 		templates.push_back(std::shared_ptr<const ObjectTemplate>(tmpl)); | 		templates.push_back(std::shared_ptr<const ObjectTemplate>(tmpl)); | ||||||
| 	} | 	} | ||||||
| 		catch (const std::exception & e) |  | ||||||
| 		{ |  | ||||||
| 			logGlobal->warn("Failed to load terrains for object %s: %s", entry.first, e.what()); |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	for(const JsonNode & node : input["sounds"]["ambient"].Vector()) | 	for(const JsonNode & node : input["sounds"]["ambient"].Vector()) | ||||||
| 		sounds.ambient.push_back(node.String()); | 		sounds.ambient.push_back(node.String()); | ||||||
|   | |||||||
| @@ -109,10 +109,6 @@ public: | |||||||
|             (void)e; |             (void)e; | ||||||
| 			return false; | 			return false; | ||||||
| 		} | 		} | ||||||
| 		catch(...) |  | ||||||
| 		{ |  | ||||||
| 			throw; |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -409,10 +409,6 @@ void CVCMIServer::threadHandleClient(std::shared_ptr<CConnection> c) | |||||||
| 	setThreadName("CVCMIServer::handleConnection"); | 	setThreadName("CVCMIServer::handleConnection"); | ||||||
| 	c->enterLobbyConnectionMode(); | 	c->enterLobbyConnectionMode(); | ||||||
|  |  | ||||||
| #ifndef _MSC_VER |  | ||||||
| 	try |  | ||||||
| 	{ |  | ||||||
| #endif |  | ||||||
| 	while(c->connected) | 	while(c->connected) | ||||||
| 	{ | 	{ | ||||||
| 		CPack * pack; | 		CPack * pack; | ||||||
| @@ -423,7 +419,11 @@ void CVCMIServer::threadHandleClient(std::shared_ptr<CConnection> c) | |||||||
| 		} | 		} | ||||||
| 		catch(boost::system::system_error & e) | 		catch(boost::system::system_error & e) | ||||||
| 		{ | 		{ | ||||||
|  | 			if (e.code() == boost::asio::error::eof) | ||||||
|  | 				logNetwork->error("Network error receiving a pack. Connection has been closed"); | ||||||
|  | 			else | ||||||
| 				logNetwork->error("Network error receiving a pack. Connection %s dies. What happened: %s", c->toString(), e.what()); | 				logNetwork->error("Network error receiving a pack. Connection %s dies. What happened: %s", c->toString(), e.what()); | ||||||
|  |  | ||||||
| 			hangingConnections.insert(c); | 			hangingConnections.insert(c); | ||||||
| 			connections.erase(c); | 			connections.erase(c); | ||||||
| 			if(connections.empty() || hostClient == c) | 			if(connections.empty() || hostClient == c) | ||||||
| @@ -439,21 +439,6 @@ void CVCMIServer::threadHandleClient(std::shared_ptr<CConnection> c) | |||||||
| 		CVCMIServerPackVisitor visitor(*this, this->gh); | 		CVCMIServerPackVisitor visitor(*this, this->gh); | ||||||
| 		pack->visit(visitor); | 		pack->visit(visitor); | ||||||
| 	} | 	} | ||||||
| #ifndef _MSC_VER |  | ||||||
| 	} |  | ||||||
| 	catch(const std::exception & e) |  | ||||||
| 	{ |  | ||||||
| 		(void)e; |  | ||||||
| 		boost::unique_lock<boost::recursive_mutex> queueLock(mx); |  | ||||||
| 		logNetwork->error("%s dies... \nWhat happened: %s", c->toString(), e.what()); |  | ||||||
| 	} |  | ||||||
| 	catch(...) |  | ||||||
| 	{ |  | ||||||
| 		state = EServerState::SHUTDOWN; |  | ||||||
| 		handleException(); |  | ||||||
| 		throw; |  | ||||||
| 	} |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| 	boost::unique_lock<boost::recursive_mutex> queueLock(mx); | 	boost::unique_lock<boost::recursive_mutex> queueLock(mx); | ||||||
|  |  | ||||||
| @@ -1022,7 +1007,7 @@ static void handleCommandOptions(int argc, const char * argv[], boost::program_o | |||||||
| 		{ | 		{ | ||||||
| 			po::store(po::parse_command_line(argc, argv, opts), options); | 			po::store(po::parse_command_line(argc, argv, opts), options); | ||||||
| 		} | 		} | ||||||
| 		catch(std::exception & e) | 		catch(po::error & e) | ||||||
| 		{ | 		{ | ||||||
| 			std::cerr << "Failure during parsing command-line options:\n" << e.what() << std::endl; | 			std::cerr << "Failure during parsing command-line options:\n" << e.what() << std::endl; | ||||||
| 		} | 		} | ||||||
| @@ -1113,10 +1098,6 @@ int main(int argc, const char * argv[]) | |||||||
| 			logNetwork->error(e.what()); | 			logNetwork->error(e.what()); | ||||||
| 			server.state = EServerState::SHUTDOWN; | 			server.state = EServerState::SHUTDOWN; | ||||||
| 		} | 		} | ||||||
| 		catch(...) |  | ||||||
| 		{ |  | ||||||
| 			handleException(); |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 	catch(boost::system::system_error & e) | 	catch(boost::system::system_error & e) | ||||||
| 	{ | 	{ | ||||||
|   | |||||||
| @@ -175,7 +175,7 @@ void PlayerMessageProcessor::cheatGiveArmy(PlayerColor player, const CGHeroInsta | |||||||
| 	{ | 	{ | ||||||
| 		amountPerSlot = std::stol(words.at(1)); | 		amountPerSlot = std::stol(words.at(1)); | ||||||
| 	} | 	} | ||||||
| 	catch(std::exception&) | 	catch(std::logic_error&) | ||||||
| 	{ | 	{ | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -233,7 +233,7 @@ void PlayerMessageProcessor::cheatLevelup(PlayerColor player, const CGHeroInstan | |||||||
| 	{ | 	{ | ||||||
| 		levelsToGain = std::stol(words.at(0)); | 		levelsToGain = std::stol(words.at(0)); | ||||||
| 	} | 	} | ||||||
| 	catch(std::exception&) | 	catch(std::logic_error&) | ||||||
| 	{ | 	{ | ||||||
| 		levelsToGain = 1; | 		levelsToGain = 1; | ||||||
| 	} | 	} | ||||||
| @@ -252,7 +252,7 @@ void PlayerMessageProcessor::cheatExperience(PlayerColor player, const CGHeroIns | |||||||
| 	{ | 	{ | ||||||
| 		expAmountProcessed = std::stol(words.at(0)); | 		expAmountProcessed = std::stol(words.at(0)); | ||||||
| 	} | 	} | ||||||
| 	catch(std::exception&) | 	catch(std::logic_error&) | ||||||
| 	{ | 	{ | ||||||
| 		expAmountProcessed = 10000; | 		expAmountProcessed = 10000; | ||||||
| 	} | 	} | ||||||
| @@ -271,7 +271,7 @@ void PlayerMessageProcessor::cheatMovement(PlayerColor player, const CGHeroInsta | |||||||
| 	{ | 	{ | ||||||
| 		smp.val = std::stol(words.at(0));; | 		smp.val = std::stol(words.at(0));; | ||||||
| 	} | 	} | ||||||
| 	catch(std::exception&) | 	catch(std::logic_error&) | ||||||
| 	{ | 	{ | ||||||
| 		smp.val = 1000000; | 		smp.val = 1000000; | ||||||
| 	} | 	} | ||||||
| @@ -293,7 +293,7 @@ void PlayerMessageProcessor::cheatResources(PlayerColor player, std::vector<std: | |||||||
| 	{ | 	{ | ||||||
| 		baseResourceAmount = std::stol(words.at(0));; | 		baseResourceAmount = std::stol(words.at(0));; | ||||||
| 	} | 	} | ||||||
| 	catch(std::exception&) | 	catch(std::logic_error&) | ||||||
| 	{ | 	{ | ||||||
| 		baseResourceAmount = 100; | 		baseResourceAmount = 100; | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user