Handle missing strings more gracefully (#1114)

This commit is contained in:
Aaron van Geffen 2021-08-17 13:20:30 +02:00 committed by GitHub
parent a48d0c7c74
commit f4d0d9215c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -1,5 +1,6 @@
#include "StringManager.h"
#include "../Config.h"
#include "../Console.h"
#include "../Date.h"
#include "../GameCommands/GameCommands.h"
#include "../Interop/Interop.hpp"
@ -550,7 +551,10 @@ namespace OpenLoco::StringManager
const char* sourceStr = getString(id);
if (sourceStr == nullptr)
{
throw std::runtime_error("Got a nullptr for string id " + std::to_string(id) + " -- cowardly refusing");
sprintf(buffer, "(missing string id: %d)", id);
Console::log("formatString: nullptr for string id: %d", id);
buffer += strlen(buffer);
return buffer;
}
buffer = formatStringPart(buffer, sourceStr, args);
@ -586,7 +590,10 @@ namespace OpenLoco::StringManager
}
else
{
throw std::out_of_range("formatString: invalid string id: " + std::to_string((uint32_t)id));
sprintf(buffer, "(invalid string id: %d)", id);
Console::log("formatString: invalid string id: %d", id);
buffer += strlen(buffer);
return buffer;
}
}