refactor: remove use of raw nonstd:: (#6690)

Reviewed-by: Nerixyz <nerixdev@outlook.de>
This commit is contained in:
pajlada
2025-12-30 11:06:10 +01:00
committed by GitHub
parent 6741d5e359
commit 864216a32e
7 changed files with 31 additions and 34 deletions
@@ -58,14 +58,14 @@ void PrintTo(const PerformChannelAction &a, std::ostream *os)
<< ", duration:" << std::to_string(a.duration) << '}'; << ", duration:" << std::to_string(a.duration) << '}';
} }
nonstd::expected<std::vector<PerformChannelAction>, QString> parseChannelAction( Expected<std::vector<PerformChannelAction>, QString> parseChannelAction(
const CommandContext &ctx, const QString &command, const QString &usage, const CommandContext &ctx, const QString &command, const QString &usage,
bool withDuration, bool withReason) bool withDuration, bool withReason)
{ {
if (ctx.channel == nullptr) if (ctx.channel == nullptr)
{ {
// A ban action must be performed with a channel as a context // A ban action must be performed with a channel as a context
return nonstd::make_unexpected( return makeUnexpected(
"A " % command % "A " % command %
" action must be performed with a channel as a context"); " action must be performed with a channel as a context");
} }
@@ -93,7 +93,7 @@ nonstd::expected<std::vector<PerformChannelAction>, QString> parseChannelAction(
auto positionalArguments = parser.positionalArguments(); auto positionalArguments = parser.positionalArguments();
if (positionalArguments.isEmpty()) if (positionalArguments.isEmpty())
{ {
return nonstd::make_unexpected("Missing target - " % usage); return makeUnexpected("Missing target - " % usage);
} }
auto [targetUserName, targetUserID] = auto [targetUserName, targetUserID] =
@@ -121,7 +121,7 @@ nonstd::expected<std::vector<PerformChannelAction>, QString> parseChannelAction(
base.duration = (int)parseDurationToSeconds(durationStr); base.duration = (int)parseDurationToSeconds(durationStr);
if (base.duration <= 0) if (base.duration <= 0)
{ {
return nonstd::make_unexpected("Invalid duration - " % usage); return makeUnexpected("Invalid duration - " % usage);
} }
if (withReason) if (withReason)
{ {
@@ -144,8 +144,8 @@ nonstd::expected<std::vector<PerformChannelAction>, QString> parseChannelAction(
{ {
if (ctx.twitchChannel == nullptr) if (ctx.twitchChannel == nullptr)
{ {
return nonstd::make_unexpected( return makeUnexpected("The " % command %
"The " % command % " command only works in Twitch channels"); " command only works in Twitch channels");
} }
actions.push_back(PerformChannelAction{ actions.push_back(PerformChannelAction{
@@ -64,7 +64,7 @@ std::ostream &operator<<(std::ostream &os, const IncompleteHelixUser &u);
// NOLINTNEXTLINE(readability-identifier-naming) // NOLINTNEXTLINE(readability-identifier-naming)
void PrintTo(const PerformChannelAction &a, std::ostream *os); void PrintTo(const PerformChannelAction &a, std::ostream *os);
nonstd::expected<std::vector<PerformChannelAction>, QString> parseChannelAction( Expected<std::vector<PerformChannelAction>, QString> parseChannelAction(
const CommandContext &ctx, const QString &command, const QString &usage, const CommandContext &ctx, const QString &command, const QString &usage,
bool withDuration, bool withReason); bool withDuration, bool withReason);
+1 -1
View File
@@ -450,7 +450,7 @@ std::pair<bool, QStringList> PluginController::updateCustomCompletions(
qCDebug(chatterinoLua) qCDebug(chatterinoLua)
<< "Got error from plugin " << pl->meta.name << "Got error from plugin " << pl->meta.name
<< " while refreshing tab completion: " << " while refreshing tab completion: "
<< errOrList.get_unexpected().error(); << errOrList.error();
continue; continue;
} }
+10 -14
View File
@@ -1,10 +1,10 @@
#pragma once #pragma once
#ifdef CHATTERINO_HAVE_PLUGINS #ifdef CHATTERINO_HAVE_PLUGINS
# include "util/Expected.hpp"
# include "util/FunctionRef.hpp" # include "util/FunctionRef.hpp"
# include "util/QMagicEnum.hpp" # include "util/QMagicEnum.hpp"
# include "util/TypeName.hpp" # include "util/TypeName.hpp"
# include <nonstd/expected.hpp>
# include <QObject> # include <QObject>
# include <QString> # include <QString>
# include <QStringBuilder> # include <QStringBuilder>
@@ -71,8 +71,7 @@ QString errorResultToString(const sol::protected_function_result &result);
/// `std::optional<T>` means nil|LuaEquiv<T> (or zero returns) /// `std::optional<T>` means nil|LuaEquiv<T> (or zero returns)
/// A return type that doesn't match returns an error /// A return type that doesn't match returns an error
template <typename T, typename... Args> template <typename T, typename... Args>
inline nonstd::expected_lite::expected<T, QString> tryCall(const auto &function, inline Expected<T, QString> tryCall(const auto &function, Args &&...args)
Args &&...args)
requires(std::same_as<std::remove_cvref_t<decltype(function)>, requires(std::same_as<std::remove_cvref_t<decltype(function)>,
sol::protected_function> || sol::protected_function> ||
std::same_as<std::remove_cvref_t<decltype(function)>, std::same_as<std::remove_cvref_t<decltype(function)>,
@@ -82,8 +81,7 @@ inline nonstd::expected_lite::expected<T, QString> tryCall(const auto &function,
function(std::forward<Args>(args)...); function(std::forward<Args>(args)...);
if (!result.valid()) if (!result.valid())
{ {
return nonstd::expected_lite::make_unexpected( return makeUnexpected(errorResultToString(result));
errorResultToString(result));
} }
if constexpr (std::is_same_v<T, void>) if constexpr (std::is_same_v<T, void>)
@@ -101,10 +99,9 @@ inline nonstd::expected_lite::expected<T, QString> tryCall(const auto &function,
} }
if (result.return_count() > 1) if (result.return_count() > 1)
{ {
return nonstd::expected_lite::make_unexpected( return makeUnexpected(u"Expected one value to be returned but " %
u"Expected one value to be returned but " % QString::number(result.return_count()) %
QString::number(result.return_count()) % u" values were returned");
u" values were returned");
} }
try try
@@ -122,7 +119,7 @@ inline nonstd::expected_lite::expected<T, QString> tryCall(const auto &function,
if (!ret) if (!ret)
{ {
auto t = type_name<T>(); auto t = type_name<T>();
return nonstd::expected_lite::make_unexpected( return makeUnexpected(
u"Expected " % QLatin1String(t.data(), t.size()) % u"Expected " % QLatin1String(t.data(), t.size()) %
u" to be returned but " % u" to be returned but " %
qmagicenum::enumName(result.get_type()) % qmagicenum::enumName(result.get_type()) %
@@ -137,7 +134,7 @@ inline nonstd::expected_lite::expected<T, QString> tryCall(const auto &function,
if (!ret) if (!ret)
{ {
auto t = type_name<T>(); auto t = type_name<T>();
return nonstd::expected_lite::make_unexpected( return makeUnexpected(
u"Expected " % QLatin1String(t.data(), t.size()) % u"Expected " % QLatin1String(t.data(), t.size()) %
u" to be returned but " % u" to be returned but " %
qmagicenum::enumName(result.get_type()) % qmagicenum::enumName(result.get_type()) %
@@ -148,8 +145,7 @@ inline nonstd::expected_lite::expected<T, QString> tryCall(const auto &function,
} }
catch (std::runtime_error &e) catch (std::runtime_error &e)
{ {
return nonstd::expected_lite::make_unexpected( return makeUnexpected(QString::fromUtf8(e.what()));
QString::fromUtf8(e.what()));
} }
// non other exceptions we let it explode // non other exceptions we let it explode
} }
@@ -158,7 +154,7 @@ inline nonstd::expected_lite::expected<T, QString> tryCall(const auto &function,
void logError(Plugin *plugin, QStringView context, const QString &msg); void logError(Plugin *plugin, QStringView context, const QString &msg);
template <typename T> template <typename T>
bool hasValueOrLog(const nonstd::expected<T, QString> &res, QStringView context, bool hasValueOrLog(const Expected<T, QString> &res, QStringView context,
Plugin *plugin) Plugin *plugin)
{ {
if (!res.has_value()) if (!res.has_value())
+4 -3
View File
@@ -93,9 +93,10 @@ void registerNmManifest([[maybe_unused]] const Paths &paths,
namespace chatterino::nm::detail { namespace chatterino::nm::detail {
nonstd::expected<void, WriteManifestError> writeManifestTo( Expected<void, WriteManifestError> writeManifestTo(QString directory,
QString directory, const QString &nmDirectory, const QString &filename, const QString &nmDirectory,
const QJsonDocument &json) const QString &filename,
const QJsonDocument &json)
{ {
if (directory.startsWith('~')) if (directory.startsWith('~'))
{ {
+4 -3
View File
@@ -16,9 +16,10 @@ enum class WriteManifestError : std::uint8_t {
FailedToCreateFile, FailedToCreateFile,
}; };
nonstd::expected<void, WriteManifestError> writeManifestTo( Expected<void, WriteManifestError> writeManifestTo(QString directory,
QString directory, const QString &nmDirectory, const QString &filename, const QString &nmDirectory,
const QJsonDocument &json); const QString &filename,
const QJsonDocument &json);
} // namespace chatterino::nm::detail } // namespace chatterino::nm::detail
+5 -6
View File
@@ -158,7 +158,7 @@ ExpectedStr<QJsonObject> validateImportJson(const QString &clipboardText)
{ {
if (clipboardText.isEmpty()) if (clipboardText.isEmpty())
{ {
return nonstd::make_unexpected("Clipboard must not be empty"); return makeUnexpected("Clipboard must not be empty");
} }
QJsonParseError parseError; QJsonParseError parseError;
@@ -167,25 +167,24 @@ ExpectedStr<QJsonObject> validateImportJson(const QString &clipboardText)
if (parseError.error != QJsonParseError::NoError) if (parseError.error != QJsonParseError::NoError)
{ {
return nonstd::make_unexpected("Clipboard did not contain valid JSON"); return makeUnexpected("Clipboard did not contain valid JSON");
} }
if (!doc.isObject()) if (!doc.isObject())
{ {
return nonstd::make_unexpected("JSON must be an object"); return makeUnexpected("JSON must be an object");
} }
auto settingsObj = doc.object(); auto settingsObj = doc.object();
if (!settingsObj.contains("Version")) if (!settingsObj.contains("Version"))
{ {
return nonstd::make_unexpected("JSON must contain the 'Version' key"); return makeUnexpected("JSON must contain the 'Version' key");
} }
if (!settingsObj.contains("RequestURL")) if (!settingsObj.contains("RequestURL"))
{ {
return nonstd::make_unexpected( return makeUnexpected("JSON must contain the 'RequestURL' key");
"JSON must contain the 'RequestURL' key");
} }
return settingsObj; return settingsObj;