mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
chore: warn when parsing environment variable fails (#3904)
* chore: warn when parsing environment variable fails * doc: update changelog
This commit is contained in:
parent
ebc7852f9f
commit
2dd37ca210
|
@ -26,6 +26,7 @@
|
|||
- Minor: Removed total views from the usercard, as Twitch no longer updates the number. (#3792)
|
||||
- Minor: Add Quick Switcher item to open a channel in a new popup window. (#3828)
|
||||
- Minor: Reduced GIF frame window from 30ms to 20ms, causing fewer frame skips in animated emotes. (#3886)
|
||||
- Minor: Warn when parsing an environment variable fails. (#3904)
|
||||
- Bugfix: Fix crash that can occur when closing and quickly reopening a split, then running a command. (#3852)
|
||||
- Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716)
|
||||
- Bugfix: Fix crash that can occur when changing channels. (#3799)
|
||||
|
|
|
@ -332,6 +332,7 @@ set(SOURCE_FILES
|
|||
util/StreamerMode.hpp
|
||||
util/Twitch.cpp
|
||||
util/Twitch.hpp
|
||||
util/TypeName.hpp
|
||||
util/WindowsHelper.cpp
|
||||
util/WindowsHelper.hpp
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
34
src/util/TypeName.hpp
Normal file
34
src/util/TypeName.hpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
// Adapted from: https://stackoverflow.com/a/56766138.
|
||||
// NOTE: Relies on the "magic" prefixes and suffixes. There are implementations
|
||||
// that attempt to manually detect these (linked in the SO answer above) but
|
||||
// they seemed too complex for the scope we have here.
|
||||
template <typename T>
|
||||
constexpr auto type_name()
|
||||
{
|
||||
std::string_view name, prefix, suffix;
|
||||
#ifdef __clang__
|
||||
name = __PRETTY_FUNCTION__;
|
||||
prefix = "auto chatterino::type_name() [T = ";
|
||||
suffix = "]";
|
||||
#elif defined(__GNUC__)
|
||||
name = __PRETTY_FUNCTION__;
|
||||
prefix = "constexpr auto chatterino::type_name() [with T = ";
|
||||
suffix = "]";
|
||||
#elif defined(_MSC_VER)
|
||||
name = __FUNCSIG__;
|
||||
prefix = "auto __cdecl chatterino::type_name<";
|
||||
suffix = ">(void)";
|
||||
#endif
|
||||
name.remove_prefix(prefix.size());
|
||||
name.remove_suffix(suffix.size());
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
Loading…
Reference in a new issue