diff --git a/src/controllers/commands/common/ChannelAction.cpp b/src/controllers/commands/common/ChannelAction.cpp index 1cdfb0e6..0d3af06b 100644 --- a/src/controllers/commands/common/ChannelAction.cpp +++ b/src/controllers/commands/common/ChannelAction.cpp @@ -58,14 +58,14 @@ void PrintTo(const PerformChannelAction &a, std::ostream *os) << ", duration:" << std::to_string(a.duration) << '}'; } -nonstd::expected, QString> parseChannelAction( +Expected, 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, 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, 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, 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{ diff --git a/src/controllers/commands/common/ChannelAction.hpp b/src/controllers/commands/common/ChannelAction.hpp index 10e908ed..030c85bb 100644 --- a/src/controllers/commands/common/ChannelAction.hpp +++ b/src/controllers/commands/common/ChannelAction.hpp @@ -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, QString> parseChannelAction( +Expected, QString> parseChannelAction( const CommandContext &ctx, const QString &command, const QString &usage, bool withDuration, bool withReason); diff --git a/src/controllers/plugins/PluginController.cpp b/src/controllers/plugins/PluginController.cpp index 1338f2f4..7afe5484 100644 --- a/src/controllers/plugins/PluginController.cpp +++ b/src/controllers/plugins/PluginController.cpp @@ -450,7 +450,7 @@ std::pair PluginController::updateCustomCompletions( qCDebug(chatterinoLua) << "Got error from plugin " << pl->meta.name << " while refreshing tab completion: " - << errOrList.get_unexpected().error(); + << errOrList.error(); continue; } diff --git a/src/controllers/plugins/SolTypes.hpp b/src/controllers/plugins/SolTypes.hpp index fd88a47b..661c59b0 100644 --- a/src/controllers/plugins/SolTypes.hpp +++ b/src/controllers/plugins/SolTypes.hpp @@ -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 # include # include # include @@ -71,8 +71,7 @@ QString errorResultToString(const sol::protected_function_result &result); /// `std::optional` means nil|LuaEquiv (or zero returns) /// A return type that doesn't match returns an error template -inline nonstd::expected_lite::expected tryCall(const auto &function, - Args &&...args) +inline Expected tryCall(const auto &function, Args &&...args) requires(std::same_as, sol::protected_function> || std::same_as, @@ -82,8 +81,7 @@ inline nonstd::expected_lite::expected tryCall(const auto &function, function(std::forward(args)...); if (!result.valid()) { - return nonstd::expected_lite::make_unexpected( - errorResultToString(result)); + return makeUnexpected(errorResultToString(result)); } if constexpr (std::is_same_v) @@ -101,10 +99,9 @@ inline nonstd::expected_lite::expected tryCall(const auto &function, } if (result.return_count() > 1) { - return nonstd::expected_lite::make_unexpected( - u"Expected one value to be returned but " % - QString::number(result.return_count()) % - u" values were returned"); + return makeUnexpected(u"Expected one value to be returned but " % + QString::number(result.return_count()) % + u" values were returned"); } try @@ -122,7 +119,7 @@ inline nonstd::expected_lite::expected tryCall(const auto &function, if (!ret) { auto t = type_name(); - 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 tryCall(const auto &function, if (!ret) { auto t = type_name(); - 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 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 tryCall(const auto &function, void logError(Plugin *plugin, QStringView context, const QString &msg); template -bool hasValueOrLog(const nonstd::expected &res, QStringView context, +bool hasValueOrLog(const Expected &res, QStringView context, Plugin *plugin) { if (!res.has_value()) diff --git a/src/singletons/NativeMessaging.cpp b/src/singletons/NativeMessaging.cpp index e5fb32ab..5314c83e 100644 --- a/src/singletons/NativeMessaging.cpp +++ b/src/singletons/NativeMessaging.cpp @@ -93,9 +93,10 @@ void registerNmManifest([[maybe_unused]] const Paths &paths, namespace chatterino::nm::detail { -nonstd::expected writeManifestTo( - QString directory, const QString &nmDirectory, const QString &filename, - const QJsonDocument &json) +Expected writeManifestTo(QString directory, + const QString &nmDirectory, + const QString &filename, + const QJsonDocument &json) { if (directory.startsWith('~')) { diff --git a/src/singletons/NativeMessaging.hpp b/src/singletons/NativeMessaging.hpp index 276210de..5b4b55c4 100644 --- a/src/singletons/NativeMessaging.hpp +++ b/src/singletons/NativeMessaging.hpp @@ -16,9 +16,10 @@ enum class WriteManifestError : std::uint8_t { FailedToCreateFile, }; -nonstd::expected writeManifestTo( - QString directory, const QString &nmDirectory, const QString &filename, - const QJsonDocument &json); +Expected writeManifestTo(QString directory, + const QString &nmDirectory, + const QString &filename, + const QJsonDocument &json); } // namespace chatterino::nm::detail diff --git a/src/util/ImageUploader.cpp b/src/util/ImageUploader.cpp index c9b26826..6b2ae17c 100644 --- a/src/util/ImageUploader.cpp +++ b/src/util/ImageUploader.cpp @@ -158,7 +158,7 @@ ExpectedStr 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 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;