chore: warn when parsing environment variable fails (#3904)

* chore: warn when parsing environment variable fails

* doc: update changelog
This commit is contained in:
Leon Richardt
2022-08-06 13:38:10 +02:00
committed by GitHub
parent ebc7852f9f
commit 2dd37ca210
6 changed files with 69 additions and 0 deletions
+31
View File
@@ -1,11 +1,38 @@
#include "common/Env.hpp"
#include "common/QLogging.hpp"
#include "util/TypeName.hpp"
#include <QVariant>
namespace chatterino {
namespace {
template <typename T>
void warn(const char *envName, T defaultValue)
{
auto *envString = std::getenv(envName);
if (!envString)
{
// This function is not supposed to be used for non-existant
// environment variables.
return;
}
const auto typeName = QString::fromStdString(
std::string(type_name<decltype(defaultValue)>()));
qCWarning(chatterinoEnv).noquote()
<< QStringLiteral(
"Cannot parse value '%1' of environment variable '%2' "
"as a %3, reverting to default value '%4'")
.arg(envString)
.arg(envName)
.arg(typeName)
.arg(defaultValue);
}
QString readStringEnv(const char *envName, QString defaultValue)
{
auto envString = std::getenv(envName);
@@ -28,6 +55,10 @@ namespace {
{
return val;
}
else
{
warn(envName, defaultValue);
}
}
return defaultValue;