refactor: remove use of raw nonstd:: (#6690)
Reviewed-by: Nerixyz <nerixdev@outlook.de>
This commit is contained in:
@@ -58,14 +58,14 @@ void PrintTo(const PerformChannelAction &a, std::ostream *os)
|
||||
<< ", 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,
|
||||
bool withDuration, bool withReason)
|
||||
{
|
||||
if (ctx.channel == nullptr)
|
||||
{
|
||||
// A ban action must be performed with a channel as a context
|
||||
return nonstd::make_unexpected(
|
||||
return makeUnexpected(
|
||||
"A " % command %
|
||||
" 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();
|
||||
if (positionalArguments.isEmpty())
|
||||
{
|
||||
return nonstd::make_unexpected("Missing target - " % usage);
|
||||
return makeUnexpected("Missing target - " % usage);
|
||||
}
|
||||
|
||||
auto [targetUserName, targetUserID] =
|
||||
@@ -121,7 +121,7 @@ nonstd::expected<std::vector<PerformChannelAction>, QString> parseChannelAction(
|
||||
base.duration = (int)parseDurationToSeconds(durationStr);
|
||||
if (base.duration <= 0)
|
||||
{
|
||||
return nonstd::make_unexpected("Invalid duration - " % usage);
|
||||
return makeUnexpected("Invalid duration - " % usage);
|
||||
}
|
||||
if (withReason)
|
||||
{
|
||||
@@ -144,8 +144,8 @@ nonstd::expected<std::vector<PerformChannelAction>, QString> parseChannelAction(
|
||||
{
|
||||
if (ctx.twitchChannel == nullptr)
|
||||
{
|
||||
return nonstd::make_unexpected(
|
||||
"The " % command % " command only works in Twitch channels");
|
||||
return makeUnexpected("The " % command %
|
||||
" command only works in Twitch channels");
|
||||
}
|
||||
|
||||
actions.push_back(PerformChannelAction{
|
||||
|
||||
@@ -64,7 +64,7 @@ std::ostream &operator<<(std::ostream &os, const IncompleteHelixUser &u);
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
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,
|
||||
bool withDuration, bool withReason);
|
||||
|
||||
|
||||
@@ -450,7 +450,7 @@ std::pair<bool, QStringList> PluginController::updateCustomCompletions(
|
||||
qCDebug(chatterinoLua)
|
||||
<< "Got error from plugin " << pl->meta.name
|
||||
<< " while refreshing tab completion: "
|
||||
<< errOrList.get_unexpected().error();
|
||||
<< errOrList.error();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
# include "util/Expected.hpp"
|
||||
# include "util/FunctionRef.hpp"
|
||||
# include "util/QMagicEnum.hpp"
|
||||
# include "util/TypeName.hpp"
|
||||
|
||||
# include <nonstd/expected.hpp>
|
||||
# include <QObject>
|
||||
# include <QString>
|
||||
# include <QStringBuilder>
|
||||
@@ -71,8 +71,7 @@ QString errorResultToString(const sol::protected_function_result &result);
|
||||
/// `std::optional<T>` means nil|LuaEquiv<T> (or zero returns)
|
||||
/// A return type that doesn't match returns an error
|
||||
template <typename T, typename... Args>
|
||||
inline nonstd::expected_lite::expected<T, QString> tryCall(const auto &function,
|
||||
Args &&...args)
|
||||
inline Expected<T, QString> tryCall(const auto &function, Args &&...args)
|
||||
requires(std::same_as<std::remove_cvref_t<decltype(function)>,
|
||||
sol::protected_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)...);
|
||||
if (!result.valid())
|
||||
{
|
||||
return nonstd::expected_lite::make_unexpected(
|
||||
errorResultToString(result));
|
||||
return makeUnexpected(errorResultToString(result));
|
||||
}
|
||||
|
||||
if constexpr (std::is_same_v<T, void>)
|
||||
@@ -101,8 +99,7 @@ inline nonstd::expected_lite::expected<T, QString> tryCall(const auto &function,
|
||||
}
|
||||
if (result.return_count() > 1)
|
||||
{
|
||||
return nonstd::expected_lite::make_unexpected(
|
||||
u"Expected one value to be returned but " %
|
||||
return makeUnexpected(u"Expected one value to be returned but " %
|
||||
QString::number(result.return_count()) %
|
||||
u" values were returned");
|
||||
}
|
||||
@@ -122,7 +119,7 @@ inline nonstd::expected_lite::expected<T, QString> tryCall(const auto &function,
|
||||
if (!ret)
|
||||
{
|
||||
auto t = type_name<T>();
|
||||
return nonstd::expected_lite::make_unexpected(
|
||||
return makeUnexpected(
|
||||
u"Expected " % QLatin1String(t.data(), t.size()) %
|
||||
u" to be returned but " %
|
||||
qmagicenum::enumName(result.get_type()) %
|
||||
@@ -137,7 +134,7 @@ inline nonstd::expected_lite::expected<T, QString> tryCall(const auto &function,
|
||||
if (!ret)
|
||||
{
|
||||
auto t = type_name<T>();
|
||||
return nonstd::expected_lite::make_unexpected(
|
||||
return makeUnexpected(
|
||||
u"Expected " % QLatin1String(t.data(), t.size()) %
|
||||
u" to be returned but " %
|
||||
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)
|
||||
{
|
||||
return nonstd::expected_lite::make_unexpected(
|
||||
QString::fromUtf8(e.what()));
|
||||
return makeUnexpected(QString::fromUtf8(e.what()));
|
||||
}
|
||||
// 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);
|
||||
|
||||
template <typename T>
|
||||
bool hasValueOrLog(const nonstd::expected<T, QString> &res, QStringView context,
|
||||
bool hasValueOrLog(const Expected<T, QString> &res, QStringView context,
|
||||
Plugin *plugin)
|
||||
{
|
||||
if (!res.has_value())
|
||||
|
||||
@@ -93,8 +93,9 @@ void registerNmManifest([[maybe_unused]] const Paths &paths,
|
||||
|
||||
namespace chatterino::nm::detail {
|
||||
|
||||
nonstd::expected<void, WriteManifestError> writeManifestTo(
|
||||
QString directory, const QString &nmDirectory, const QString &filename,
|
||||
Expected<void, WriteManifestError> writeManifestTo(QString directory,
|
||||
const QString &nmDirectory,
|
||||
const QString &filename,
|
||||
const QJsonDocument &json)
|
||||
{
|
||||
if (directory.startsWith('~'))
|
||||
|
||||
@@ -16,8 +16,9 @@ enum class WriteManifestError : std::uint8_t {
|
||||
FailedToCreateFile,
|
||||
};
|
||||
|
||||
nonstd::expected<void, WriteManifestError> writeManifestTo(
|
||||
QString directory, const QString &nmDirectory, const QString &filename,
|
||||
Expected<void, WriteManifestError> writeManifestTo(QString directory,
|
||||
const QString &nmDirectory,
|
||||
const QString &filename,
|
||||
const QJsonDocument &json);
|
||||
|
||||
} // namespace chatterino::nm::detail
|
||||
|
||||
@@ -158,7 +158,7 @@ ExpectedStr<QJsonObject> validateImportJson(const QString &clipboardText)
|
||||
{
|
||||
if (clipboardText.isEmpty())
|
||||
{
|
||||
return nonstd::make_unexpected("Clipboard must not be empty");
|
||||
return makeUnexpected("Clipboard must not be empty");
|
||||
}
|
||||
|
||||
QJsonParseError parseError;
|
||||
@@ -167,25 +167,24 @@ ExpectedStr<QJsonObject> validateImportJson(const QString &clipboardText)
|
||||
|
||||
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())
|
||||
{
|
||||
return nonstd::make_unexpected("JSON must be an object");
|
||||
return makeUnexpected("JSON must be an object");
|
||||
}
|
||||
|
||||
auto settingsObj = doc.object();
|
||||
|
||||
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"))
|
||||
{
|
||||
return nonstd::make_unexpected(
|
||||
"JSON must contain the 'RequestURL' key");
|
||||
return makeUnexpected("JSON must contain the 'RequestURL' key");
|
||||
}
|
||||
|
||||
return settingsObj;
|
||||
|
||||
Reference in New Issue
Block a user