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;
+1
View File
@@ -13,6 +13,7 @@ Q_LOGGING_CATEGORY(chatterinoBttv, "chatterino.bttv", logThreshold);
Q_LOGGING_CATEGORY(chatterinoCache, "chatterino.cache", logThreshold);
Q_LOGGING_CATEGORY(chatterinoCommon, "chatterino.common", logThreshold);
Q_LOGGING_CATEGORY(chatterinoEmoji, "chatterino.emoji", logThreshold);
Q_LOGGING_CATEGORY(chatterinoEnv, "chatterino.env", logThreshold);
Q_LOGGING_CATEGORY(chatterinoFfzemotes, "chatterino.ffzemotes", logThreshold);
Q_LOGGING_CATEGORY(chatterinoHelper, "chatterino.helper", logThreshold);
Q_LOGGING_CATEGORY(chatterinoHotkeys, "chatterino.hotkeys", logThreshold);
+1
View File
@@ -9,6 +9,7 @@ Q_DECLARE_LOGGING_CATEGORY(chatterinoBttv);
Q_DECLARE_LOGGING_CATEGORY(chatterinoCache);
Q_DECLARE_LOGGING_CATEGORY(chatterinoCommon);
Q_DECLARE_LOGGING_CATEGORY(chatterinoEmoji);
Q_DECLARE_LOGGING_CATEGORY(chatterinoEnv);
Q_DECLARE_LOGGING_CATEGORY(chatterinoFfzemotes);
Q_DECLARE_LOGGING_CATEGORY(chatterinoHelper);
Q_DECLARE_LOGGING_CATEGORY(chatterinoHotkeys);