1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #2403 from IvanSavenko/error_detection_fix

Attempt to fix & improve error reporting
This commit is contained in:
Ivan Savenko 2023-07-25 18:15:28 +03:00 committed by GitHub
commit 705cdb846d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 99 deletions

View File

@ -253,26 +253,6 @@ using TLockGuardRec = std::lock_guard<std::recursive_mutex>;
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
{
// combine hashes. Present in boost but not in std

View File

@ -865,8 +865,11 @@ void CServerHandler::threadHandleConnection()
}
else
{
logNetwork->error("Lost connection to server, ending listening thread!");
logNetwork->error(e.what());
if (e.code() == boost::asio::error::eof)
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)
{
state = EClientState::DISCONNECTING;

View File

@ -48,17 +48,10 @@ DLL_LINKAGE void preinitDLL(CConsoleHandler * Console, bool onlyEssential, bool
{
console = Console;
VLC = new LibClasses();
try
{
VLC->loadFilesystem(extractArchives);
settings.init();
VLC->loadModFilesystem(onlyEssential);
}
catch(...)
{
handleException();
throw;
}
VLC->loadFilesystem(extractArchives);
settings.init();
VLC->loadModFilesystem(onlyEssential);
}
DLL_LINKAGE void loadDLLClasses(bool onlyEssential)

View File

@ -569,7 +569,6 @@ void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRan
catch(...)
{
logGlobal->error("Saving random map failed with exception");
handleException();
}
}

View File

@ -220,7 +220,7 @@ public:
void write(const LogRecord & record) override;
private:
FileStream file;
boost::filesystem::fstream file;
CLogFormatter formatter;
mutable std::mutex mx;
};

View File

@ -77,15 +77,8 @@ void AObjectTypeHandler::init(const JsonNode & input)
tmpl->id = Obj(type);
tmpl->subid = subtype;
tmpl->stringID = entry.first; // FIXME: create "fullID" - type.object.template?
try
{
tmpl->readJson(entry.second);
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());
}
tmpl->readJson(entry.second);
templates.push_back(std::shared_ptr<const ObjectTemplate>(tmpl));
}
for(const JsonNode & node : input["sounds"]["ambient"].Vector())

View File

@ -109,10 +109,6 @@ public:
(void)e;
return false;
}
catch(...)
{
throw;
}
}
};

View File

@ -409,51 +409,36 @@ void CVCMIServer::threadHandleClient(std::shared_ptr<CConnection> c)
setThreadName("CVCMIServer::handleConnection");
c->enterLobbyConnectionMode();
#ifndef _MSC_VER
try
while(c->connected)
{
#endif
while(c->connected)
CPack * pack;
try
{
CPack * pack;
try
{
pack = c->retrievePack();
}
catch(boost::system::system_error & e)
{
logNetwork->error("Network error receiving a pack. Connection %s dies. What happened: %s", c->toString(), e.what());
hangingConnections.insert(c);
connections.erase(c);
if(connections.empty() || hostClient == c)
state = EServerState::SHUTDOWN;
if(gh && state == EServerState::GAMEPLAY)
{
gh->handleClientDisconnection(c);
}
break;
}
CVCMIServerPackVisitor visitor(*this, this->gh);
pack->visit(visitor);
pack = c->retrievePack();
}
#ifndef _MSC_VER
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());
hangingConnections.insert(c);
connections.erase(c);
if(connections.empty() || hostClient == c)
state = EServerState::SHUTDOWN;
if(gh && state == EServerState::GAMEPLAY)
{
gh->handleClientDisconnection(c);
}
break;
}
CVCMIServerPackVisitor visitor(*this, this->gh);
pack->visit(visitor);
}
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);
@ -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);
}
catch(std::exception & e)
catch(po::error & e)
{
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());
server.state = EServerState::SHUTDOWN;
}
catch(...)
{
handleException();
}
}
catch(boost::system::system_error & e)
{

View File

@ -175,7 +175,7 @@ void PlayerMessageProcessor::cheatGiveArmy(PlayerColor player, const CGHeroInsta
{
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));
}
catch(std::exception&)
catch(std::logic_error&)
{
levelsToGain = 1;
}
@ -252,7 +252,7 @@ void PlayerMessageProcessor::cheatExperience(PlayerColor player, const CGHeroIns
{
expAmountProcessed = std::stol(words.at(0));
}
catch(std::exception&)
catch(std::logic_error&)
{
expAmountProcessed = 10000;
}
@ -271,7 +271,7 @@ void PlayerMessageProcessor::cheatMovement(PlayerColor player, const CGHeroInsta
{
smp.val = std::stol(words.at(0));;
}
catch(std::exception&)
catch(std::logic_error&)
{
smp.val = 1000000;
}
@ -293,7 +293,7 @@ void PlayerMessageProcessor::cheatResources(PlayerColor player, std::vector<std:
{
baseResourceAmount = std::stol(words.at(0));;
}
catch(std::exception&)
catch(std::logic_error&)
{
baseResourceAmount = 100;
}