From ae0e846eababd159536532ab14f878544f6369e2 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 15 Apr 2025 10:23:32 +0200 Subject: [PATCH] Replace a few make_unexpected with ResultError Change-Id: I64637b8b43c1932dee59e37b8922c18d27c2deb9 Reviewed-by: Jarek Kobus --- .../advanceddockingsystem/dockmanager.cpp | 42 +++++++++---------- src/libs/extensionsystem/pluginspec.cpp | 24 +++++------ .../gocmdbridge/client/bridgedfileaccess.cpp | 8 ++-- .../gocmdbridge/client/cmdbridgeclient.cpp | 24 +++++------ src/libs/utils/devicefileaccess.cpp | 42 +++++++++---------- src/libs/utils/deviceshell.cpp | 8 ++-- .../utils/externalterminalprocessimpl.cpp | 6 +-- src/libs/utils/fancylineedit.cpp | 2 +- src/libs/utils/filepath.cpp | 10 ++--- src/libs/utils/filestreamermanager.cpp | 6 +-- src/libs/utils/fileutils.cpp | 2 +- src/libs/utils/lua.cpp | 2 +- src/libs/utils/macroexpander.cpp | 5 +-- src/libs/utils/osspecificaspects.h | 4 +- src/libs/utils/pathchooser.cpp | 28 ++++++------- src/libs/utils/portlist.cpp | 2 +- src/libs/utils/processinfo.cpp | 24 +++++------ src/libs/utils/result.cpp | 2 +- src/libs/utils/store.cpp | 4 +- src/libs/utils/terminalhooks.cpp | 4 +- src/libs/utils/terminalinterface.cpp | 8 ++-- src/libs/utils/theme/theme.cpp | 2 +- src/plugins/android/androidsettingswidget.cpp | 12 +++--- src/plugins/axivion/axivionplugin.cpp | 2 +- src/plugins/clangformat/clangformatutils.cpp | 19 ++++----- .../clangtools/clangtoolslogfilereader.cpp | 10 ++--- .../cmakeprojectmanager/cmakebuildsystem.cpp | 4 +- src/plugins/coreplugin/icore.cpp | 2 +- src/plugins/coreplugin/loggingviewer.cpp | 10 ++--- .../coreplugin/plugininstallwizard.cpp | 8 ++-- src/plugins/debugger/debuggeritem.cpp | 16 +++---- src/plugins/docker/dockerdevice.cpp | 8 ++-- 32 files changed, 174 insertions(+), 176 deletions(-) diff --git a/src/libs/advanceddockingsystem/dockmanager.cpp b/src/libs/advanceddockingsystem/dockmanager.cpp index e4cee5fb1ea..4e2be0a3a8f 100644 --- a/src/libs/advanceddockingsystem/dockmanager.cpp +++ b/src/libs/advanceddockingsystem/dockmanager.cpp @@ -1195,7 +1195,7 @@ Result DockManager::createWorkspace(const QString &workspaceName) Result<> result = write(filePath, saveState(workspaceName)); // TODO utils if (!result) - return make_unexpected(result.error()); + return ResultError(result.error()); Workspace workspace(filePath, false); @@ -1210,7 +1210,7 @@ Result<> DockManager::openWorkspace(const QString &fileName) Workspace *wrk = workspace(fileName); if (!wrk) - return make_unexpected(Tr::tr("Workspace \"%1\" does not exist.").arg(fileName)); + return ResultError(Tr::tr("Workspace \"%1\" does not exist.").arg(fileName)); // Do nothing if workspace is already loaded, exception if it is a preset workspace. In this // case we still want to be able to load the default workspace to undo potential user changes. @@ -1228,12 +1228,12 @@ Result<> DockManager::openWorkspace(const QString &fileName) // Try loading the file const Result data = loadWorkspace(*wrk); if (!data) - return make_unexpected(data.error()); + return ResultError(data.error()); emit openingWorkspace(wrk->fileName()); // If data was loaded from file try to restore its state if (!data->isNull() && !restoreState(*data)) - return make_unexpected(Tr::tr("Cannot restore \"%1\".").arg(wrk->filePath().toUserOutput())); + return ResultError(Tr::tr("Cannot restore \"%1\".").arg(wrk->filePath().toUserOutput())); d->m_workspace = *wrk; emit workspaceLoaded(wrk->fileName()); @@ -1248,16 +1248,16 @@ Result<> DockManager::reloadActiveWorkspace() Workspace *wrk = activeWorkspace(); if (!workspaces().contains(*wrk)) - return make_unexpected( + return ResultError( Tr::tr("Cannot reload \"%1\". It is not in the list of workspaces.") .arg(wrk->filePath().toUserOutput())); const Result data = loadWorkspace(*wrk); if (!data) - return make_unexpected(data.error()); + return ResultError(data.error()); if (!data->isNull() && !restoreState(*data)) - return make_unexpected(Tr::tr("Cannot restore \"%1\".").arg(wrk->filePath().toUserOutput())); + return ResultError(Tr::tr("Cannot restore \"%1\".").arg(wrk->filePath().toUserOutput())); emit workspaceReloaded(wrk->fileName()); @@ -1301,19 +1301,19 @@ Result DockManager::cloneWorkspace(const QString &originalFileName, Workspace *w = workspace(originalFileName); if (!w) - return make_unexpected(Tr::tr("Workspace \"%1\" does not exist.").arg(originalFileName)); + return ResultError(Tr::tr("Workspace \"%1\" does not exist.").arg(originalFileName)); const FilePath originalPath = w->filePath(); if (!originalPath.exists()) - return make_unexpected( + return ResultError( Tr::tr("Workspace \"%1\" does not exist.").arg(originalPath.toUserOutput())); const FilePath clonePath = workspaceNameToFilePath(cloneName); const Result<> copyResult = originalPath.copyFile(clonePath); if (!copyResult) - return make_unexpected(Tr::tr("Could not clone \"%1\" due to: %2") + return ResultError(Tr::tr("Could not clone \"%1\" due to: %2") .arg(originalPath.toUserOutput(), copyResult.error())); writeDisplayName(clonePath, cloneName); @@ -1329,7 +1329,7 @@ Result DockManager::renameWorkspace(const QString &originalFileName, Workspace *w = workspace(originalFileName); if (!w) - return make_unexpected(Tr::tr("Workspace \"%1\" does not exist.").arg(originalFileName)); + return ResultError(Tr::tr("Workspace \"%1\" does not exist.").arg(originalFileName)); w->setName(newName); @@ -1359,7 +1359,7 @@ Result<> DockManager::resetWorkspacePreset(const QString &fileName) Result<> DockManager::save() { if (isModeChangeState()) - return make_unexpected(Tr::tr("Cannot save workspace while in mode change state.")); + return ResultError(Tr::tr("Cannot save workspace while in mode change state.")); emit aboutToSaveWorkspace(); @@ -1390,7 +1390,7 @@ Result DockManager::importWorkspace(const QString &filePath) const FilePath sourceFilePath = FilePath::fromUserInput(filePath); if (!sourceFilePath.exists()) - return make_unexpected( + return ResultError( Tr::tr("File \"%1\" does not exist.").arg(sourceFilePath.toUserOutput())); // Extract workspace file name. Check if the workspace is already contained in the list of @@ -1402,7 +1402,7 @@ Result DockManager::importWorkspace(const QString &filePath) const Result<> copyResult = sourceFilePath.copyFile(targetFilePath); if (!copyResult) - return make_unexpected( + return ResultError( Tr::tr("Could not copy \"%1\" to \"%2\" due to: %3") .arg(filePath, targetFilePath.toUserOutput(), copyResult.error())); @@ -1424,26 +1424,26 @@ Result DockManager::exportWorkspace(const QString &targetFilePath, // Remove the file which supposed to be overwritten if (targetFile.exists()) { if (!targetFile.removeFile()) { - return make_unexpected( + return ResultError( Tr::tr("Could not remove \"%1\".").arg(targetFile.toUserOutput())); } } // Check if the target directory exists if (!targetFile.parentDir().exists()) - return make_unexpected( + return ResultError( Tr::tr("The directory \"%1\" does not exist.").arg(targetFile.parentDir().toUserOutput())); // Check if the workspace exists const FilePath workspaceFile = userDirectory().pathAppended(sourceFileName); if (!workspaceFile.exists()) - return make_unexpected( + return ResultError( Tr::tr("The workspace \"%1\" does not exist ").arg(workspaceFile.toUserOutput())); // Finally copy the workspace to the target const Result<> copyResult = workspaceFile.copyFile(targetFile); if (!copyResult) - return make_unexpected( + return ResultError( Tr::tr("Could not copy \"%1\" to \"%2\" due to: %3") .arg(sourceFileName, workspaceFile.toUserOutput(), copyResult.error())); @@ -1610,14 +1610,14 @@ Result<> DockManager::write(const FilePath &filePath, const QByteArray &data) qCInfo(adsLog) << "Write" << filePath; if (!filePath.parentDir().ensureWritableDir()) - return make_unexpected(Tr::tr("Cannot write to \"%1\".").arg(filePath.toUserOutput())); + return ResultError(Tr::tr("Cannot write to \"%1\".").arg(filePath.toUserOutput())); FileSaver fileSaver(filePath, QIODevice::Text); if (!fileSaver.hasError()) fileSaver.write(data); if (!fileSaver.finalize()) - return make_unexpected(Tr::tr("Cannot write to \"%1\" due to: %2") + return ResultError(Tr::tr("Cannot write to \"%1\" due to: %2") .arg(filePath.toUserOutput(), fileSaver.errorString())); return {}; @@ -1628,7 +1628,7 @@ Result DockManager::loadWorkspace(const Workspace &workspace) const qCInfo(adsLog) << "Load workspace" << workspace.fileName(); if (!workspace.exists()) - return make_unexpected( + return ResultError( Tr::tr("Workspace \"%1\" does not exist.").arg(workspace.filePath().toUserOutput())); return workspace.filePath().fileContents(); diff --git a/src/libs/extensionsystem/pluginspec.cpp b/src/libs/extensionsystem/pluginspec.cpp index 3e575ea1b44..301aacf5f73 100644 --- a/src/libs/extensionsystem/pluginspec.cpp +++ b/src/libs/extensionsystem/pluginspec.cpp @@ -811,11 +811,11 @@ Result> readCppPluginSpec(const FilePath &fileName) spec->d->loader->setFileName(absPath.toFSPathString()); if (spec->d->loader->fileName().isEmpty()) - return make_unexpected(::ExtensionSystem::Tr::tr("Cannot open file")); + return ResultError(::ExtensionSystem::Tr::tr("Cannot open file")); Result<> r = spec->readMetaData(spec->d->loader->metaData()); if (!r) - return make_unexpected(r.error()); + return ResultError(r.error()); return spec; } @@ -828,7 +828,7 @@ Result> readCppPluginSpec(const QStaticPlugin &plugi spec->d->staticPlugin = plugin; Result<> r = spec->readMetaData(plugin.metaData()); if (!r) - return make_unexpected(r.error()); + return ResultError(r.error()); return spec; } @@ -882,10 +882,10 @@ Result<> CppPluginSpec::readMetaData(const QJsonObject &pluginMetaData) QJsonValue value; value = pluginMetaData.value(QLatin1String("IID")); if (!value.isString()) - return make_unexpected(::ExtensionSystem::Tr::tr("No IID found")); + return ResultError(::ExtensionSystem::Tr::tr("No IID found")); if (value.toString() != PluginManager::pluginIID()) - return make_unexpected(::ExtensionSystem::Tr::tr("Expected IID \"%1\", but found \"%2\"") + return ResultError(::ExtensionSystem::Tr::tr("Expected IID \"%1\", but found \"%2\"") .arg(PluginManager::pluginIID()) .arg(value.toString())); @@ -920,9 +920,9 @@ Utils::Result<> PluginSpecPrivate::readMetaData(const QJsonObject &data) auto assign = [&data](QString &member, const char *fieldName) -> Result<> { QJsonValue value = data.value(QLatin1String(fieldName)); if (value.isUndefined()) - return make_unexpected(msgValueMissing(fieldName)); + return ResultError(msgValueMissing(fieldName)); if (!value.isString()) - return make_unexpected(msgValueIsNotAString(fieldName)); + return ResultError(msgValueIsNotAString(fieldName)); member = value.toString(); return {}; }; @@ -940,11 +940,11 @@ Utils::Result<> PluginSpecPrivate::readMetaData(const QJsonObject &data) if constexpr (isString) { if (!value.isString()) - return make_unexpected(msgValueIsNotAString(fieldName)); + return ResultError(msgValueIsNotAString(fieldName)); member = value.toString(); } else if constexpr (isBool) { if (!value.isBool()) - return make_unexpected(msgValueIsNotABool(fieldName)); + return ResultError(msgValueIsNotABool(fieldName)); member = value.toBool(); } } @@ -956,7 +956,7 @@ Utils::Result<> PluginSpecPrivate::readMetaData(const QJsonObject &data) if (value.isUndefined()) return {}; if (!readMultiLineString(value, &member)) - return make_unexpected(msgValueIsNotAMultilineString(fieldName)); + return ResultError(msgValueIsNotAMultilineString(fieldName)); return {}; }; @@ -1483,7 +1483,7 @@ QList pluginSpecsFromArchive(const Utils::FilePath &path) Result PluginSpec::filesToUninstall() const { if (isSystemPlugin()) - return make_unexpected(Tr::tr("Cannot remove system plugins.")); + return ResultError(Tr::tr("Cannot remove system plugins.")); // Try to figure out where we are ... const FilePaths pluginPaths = PluginManager::pluginPaths(); @@ -1492,7 +1492,7 @@ Result PluginSpec::filesToUninstall() const if (location().isChildOf(pluginPath)) { const FilePath rootFolder = location().relativeChildPath(pluginPath); if (rootFolder.isEmpty()) - return make_unexpected(Tr::tr("Could not determine root folder.")); + return ResultError(Tr::tr("Could not determine root folder.")); const FilePath pathToDelete = pluginPath / rootFolder.pathComponents().first().toString(); diff --git a/src/libs/gocmdbridge/client/bridgedfileaccess.cpp b/src/libs/gocmdbridge/client/bridgedfileaccess.cpp index b735d81c752..7763e13f01c 100644 --- a/src/libs/gocmdbridge/client/bridgedfileaccess.cpp +++ b/src/libs/gocmdbridge/client/bridgedfileaccess.cpp @@ -27,7 +27,7 @@ Result run(const CommandLine &cmdLine, const QByteArray &inputData = {} p.setWriteData(inputData); p.runBlocking(); if (p.exitCode() != 0) { - return make_unexpected(Tr::tr("Command failed with exit code %1: %2") + return ResultError(Tr::tr("Command failed with exit code %1: %2") .arg(p.exitCode()) .arg(p.readAllStandardOutput())); } @@ -455,7 +455,7 @@ Result FileAccess::fileContents(const FilePath &filePath, } return data; } catch (const std::exception &e) { - return make_unexpected( + return ResultError( Tr::tr("Error reading file: %1").arg(QString::fromLocal8Bit(e.what()))); } } @@ -468,7 +468,7 @@ Result FileAccess::writeFileContents(const FilePath &filePath, QTC_ASSERT_RESULT(f, return {}); return f->result(); } catch (const std::exception &e) { - return make_unexpected( + return ResultError( Tr::tr("Error writing file: %1").arg(QString::fromLocal8Bit(e.what()))); } } @@ -607,7 +607,7 @@ Result FileAccess::createTempFile(const FilePath &filePath) return result; return filePath.withNewPath(result->path()); } catch (const std::exception &e) { - return make_unexpected( + return ResultError( Tr::tr("Error creating temporary file: %1").arg(QString::fromLocal8Bit(e.what()))); } } diff --git a/src/libs/gocmdbridge/client/cmdbridgeclient.cpp b/src/libs/gocmdbridge/client/cmdbridgeclient.cpp index 294bf0fcb79..19ae46b3626 100644 --- a/src/libs/gocmdbridge/client/cmdbridgeclient.cpp +++ b/src/libs/gocmdbridge/client/cmdbridgeclient.cpp @@ -178,7 +178,7 @@ std::optional> ClientPrivate::handleWatchResults(const QVariantMap &map auto it = watchers.find(id); if (it == watchers.end()) - return make_unexpected(QString("No watcher found for id %1").arg(id)); + return ResultError(QString("No watcher found for id %1").arg(id)); auto promise = it.value(); if (!promise->isCanceled()) @@ -197,7 +197,7 @@ std::optional> ClientPrivate::handleWatchResults(const QVariantMap &map Result<> ClientPrivate::readPacket(QCborStreamReader &reader) { if (!reader.enterContainer()) - return make_unexpected(QString("The packet did not contain a container")); + return ResultError(QString("The packet did not contain a container")); Q_ASSERT(QThread::currentThread() == thread); @@ -209,10 +209,10 @@ Result<> ClientPrivate::readPacket(QCborStreamReader &reader) } if (!reader.leaveContainer()) - return make_unexpected(QString("The packet did not contain a finalized map")); + return ResultError(QString("The packet did not contain a finalized map")); if (!map.contains("Id")) { - return make_unexpected(QString("The packet did not contain an Id")); + return ResultError(QString("The packet did not contain an Id")); } auto watchHandled = handleWatchResults(map); @@ -223,7 +223,7 @@ Result<> ClientPrivate::readPacket(QCborStreamReader &reader) auto j = jobs.readLocked(); auto it = j->map.find(id); if (it == j->map.end()) - return make_unexpected( + return ResultError( QString("No job found for packet with id %1: %2") .arg(id) .arg(QString::fromUtf8(QJsonDocument::fromVariant(map).toJson()))); @@ -421,7 +421,7 @@ static Utils::Result> createJob( Errors handleErrors = Errors::Handle) { if (!d->process || !d->process->isRunning()) - return make_unexpected(Tr::tr("Bridge process not running")); + return ResultError(Tr::tr("Bridge process not running")); std::shared_ptr> promise = std::make_shared>(); QFuture future = promise->future(); @@ -515,7 +515,7 @@ Result> Client::find( { // TODO: golang's walkDir does not support automatically following symlinks. if (filter.iteratorFlags.testFlag(QDirIterator::FollowSymlinks)) - return make_unexpected(Tr::tr("FollowSymlinks is not supported")); + return ResultError(Tr::tr("FollowSymlinks is not supported")); QCborMap findArgs{ {"Type", "find"}, @@ -818,12 +818,12 @@ Utils::Result> Client::watch(const QString &pat }); if (!jobResult) - return make_unexpected(jobResult.error()); + return ResultError(jobResult.error()); try { return std::make_unique(jobResult->result()); } catch (const std::exception &e) { - return make_unexpected(QString::fromUtf8(e.what())); + return ResultError(QString::fromUtf8(e.what())); } } @@ -841,9 +841,9 @@ Utils::Result> Client::signalProcess(int pid, Utils::ControlSignal signalString = "kill"; break; case ControlSignal::KickOff: - return make_unexpected(Tr::tr("Kickoff signal is not supported")); + return ResultError(Tr::tr("Kickoff signal is not supported")); case ControlSignal::CloseWriteChannel: - return make_unexpected(Tr::tr("CloseWriteChannel signal is not supported")); + return ResultError(Tr::tr("CloseWriteChannel signal is not supported")); } return createVoidJob( @@ -942,7 +942,7 @@ Result Client::getCmdBridgePath( if (result.exists()) return result; - return make_unexpected( + return ResultError( QString(Tr::tr("No command bridge found for architecture %1-%2")).arg(type, arch)); } diff --git a/src/libs/utils/devicefileaccess.cpp b/src/libs/utils/devicefileaccess.cpp index 9391e333066..4a4bddcfd0b 100644 --- a/src/libs/utils/devicefileaccess.cpp +++ b/src/libs/utils/devicefileaccess.cpp @@ -313,7 +313,7 @@ Result DeviceFileAccess::fileContents(const FilePath &filePath, Q_UNUSED(limit) Q_UNUSED(offset) QTC_CHECK(false); - return make_unexpected( + return ResultError( Tr::tr("fileContents is not implemented for \"%1\".").arg(filePath.toUserOutput())); } @@ -323,7 +323,7 @@ Result DeviceFileAccess::writeFileContents(const FilePath &filePath, Q_UNUSED(filePath) Q_UNUSED(data) QTC_CHECK(false); - return make_unexpected( + return ResultError( Tr::tr("writeFileContents is not implemented for \"%1\".").arg(filePath.toUserOutput())); } @@ -389,7 +389,7 @@ Result DeviceFileAccess::createTempFile(const FilePath &filePath) { Q_UNUSED(filePath) QTC_CHECK(false); - return make_unexpected( + return ResultError( Tr::tr("createTempFile is not implemented for \"%1\".").arg(filePath.toUserOutput())); } @@ -397,7 +397,7 @@ Utils::Result> DeviceFileAccess::watch( const FilePath &path) const { Q_UNUSED(path); - return make_unexpected(Tr::tr("watch is not implemented.")); + return ResultError(Tr::tr("watch is not implemented.")); } QTextCodec *DeviceFileAccess::processStdOutCodec(const FilePath &executable) const @@ -566,7 +566,7 @@ Result UnavailableDeviceFileAccess::fileContents(const FilePath &fil Q_UNUSED(filePath) Q_UNUSED(limit) Q_UNUSED(offset) - return make_unexpected(unavailableMessage()); + return ResultError(unavailableMessage()); } Result UnavailableDeviceFileAccess::writeFileContents(const FilePath &filePath, @@ -574,7 +574,7 @@ Result UnavailableDeviceFileAccess::writeFileContents(const FilePath &fi { Q_UNUSED(filePath) Q_UNUSED(data) - return make_unexpected(unavailableMessage()); + return ResultError(unavailableMessage()); } FilePathInfo UnavailableDeviceFileAccess::filePathInfo(const FilePath &filePath) const @@ -630,14 +630,14 @@ std::optional UnavailableDeviceFileAccess::refersToExecutableFile( Result UnavailableDeviceFileAccess::createTempFile(const FilePath &filePath) { Q_UNUSED(filePath) - return make_unexpected(unavailableMessage()); + return ResultError(unavailableMessage()); } Result> UnavailableDeviceFileAccess::watch(const FilePath &path) const { Q_UNUSED(path); - return make_unexpected(unavailableMessage()); + return ResultError(unavailableMessage()); } // DesktopDeviceFileAccess @@ -1138,10 +1138,10 @@ Result DesktopDeviceFileAccess::fileContents(const FilePath &filePat const QString path = filePath.path(); QFile f(path); if (!f.exists()) - return make_unexpected(Tr::tr("File \"%1\" does not exist.").arg(path)); + return ResultError(Tr::tr("File \"%1\" does not exist.").arg(path)); if (!f.open(QFile::ReadOnly)) - return make_unexpected(Tr::tr("Could not open File \"%1\".").arg(path)); + return ResultError(Tr::tr("Could not open File \"%1\".").arg(path)); if (offset != 0) f.seek(offset); @@ -1151,7 +1151,7 @@ Result DesktopDeviceFileAccess::fileContents(const FilePath &filePat const QByteArray data = f.readAll(); if (f.error() != QFile::NoError) { - return make_unexpected( + return ResultError( Tr::tr("Cannot read \"%1\": %2").arg(filePath.toUserOutput(), f.errorString())); } @@ -1164,12 +1164,12 @@ Result DesktopDeviceFileAccess::writeFileContents(const FilePath &filePa QFile file(filePath.path()); const bool isOpened = file.open(QFile::WriteOnly | QFile::Truncate); if (!isOpened) - return make_unexpected( + return ResultError( Tr::tr("Could not open file \"%1\" for writing.").arg(filePath.toUserOutput())); qint64 res = file.write(data); if (res != data.size()) - return make_unexpected( + return ResultError( Tr::tr("Could not write to file \"%1\" (only %2 of %n byte(s) written).", nullptr, data.size()) @@ -1183,7 +1183,7 @@ Result DesktopDeviceFileAccess::createTempFile(const FilePath &filePat QTemporaryFile file(filePath.path()); file.setAutoRemove(false); if (!file.open()) { - return make_unexpected(Tr::tr("Could not create temporary file in \"%1\" (%2).") + return ResultError(Tr::tr("Could not create temporary file in \"%1\" (%2).") .arg(filePath.toUserOutput()) .arg(file.errorString())); } @@ -1196,7 +1196,7 @@ Utils::Result> DesktopDeviceFileAccess::watch( auto watcher = std::make_unique(path); if (watcher->error().isEmpty()) return watcher; - return make_unexpected(watcher->error()); + return ResultError(watcher->error()); } QTextCodec *DesktopDeviceFileAccess::processStdOutCodec(const FilePath &executable) const @@ -1489,12 +1489,12 @@ Result UnixDeviceFileAccess::fileContents(const FilePath &filePath, p.setCommand({dd, args, OsType::OsTypeLinux}); p.runBlocking(0s); // Run forever if (p.exitCode() != 0) { - return make_unexpected(Tr::tr("Failed reading file \"%1\": %2") + return ResultError(Tr::tr("Failed reading file \"%1\": %2") .arg(filePath.toUserOutput(), p.readAllStandardError())); } return p.rawStdOut(); #else - return make_unexpected(QString("Not implemented")); + return ResultError(QString("Not implemented")); #endif } @@ -1509,7 +1509,7 @@ Result UnixDeviceFileAccess::writeFileContents(const FilePath &filePath, RunResult result = runInShell({"dd", args, OsType::OsTypeLinux}, data); if (result.exitCode != 0) { - return make_unexpected(Tr::tr("Failed writing file \"%1\": %2") + return ResultError(Tr::tr("Failed writing file \"%1\": %2") .arg(filePath.toUserOutput(), QString::fromUtf8(result.stdErr))); } return data.size(); @@ -1530,7 +1530,7 @@ Result UnixDeviceFileAccess::createTempFile(const FilePath &filePath) const RunResult result = runInShell({"mktemp", {tmplate}, OsType::OsTypeLinux}); if (result.exitCode != 0) { - return make_unexpected( + return ResultError( Tr::tr("Failed creating temporary file \"%1\": %2") .arg(filePath.toUserOutput(), QString::fromUtf8(result.stdErr))); } @@ -1561,7 +1561,7 @@ Result UnixDeviceFileAccess::createTempFile(const FilePath &filePath) } newPath = filePath.withNewPath(tmplate); if (--maxTries == 0) { - return make_unexpected(Tr::tr("Failed creating temporary file \"%1\" (too many tries).") + return ResultError(Tr::tr("Failed creating temporary file \"%1\" (too many tries).") .arg(filePath.toUserOutput())); } } while (newPath.exists()); @@ -1569,7 +1569,7 @@ Result UnixDeviceFileAccess::createTempFile(const FilePath &filePath) const Result createResult = newPath.writeFileContents({}); if (!createResult) - return make_unexpected(createResult.error()); + return ResultError(createResult.error()); return newPath; } diff --git a/src/libs/utils/deviceshell.cpp b/src/libs/utils/deviceshell.cpp index fe46da8cda7..9da49f00582 100644 --- a/src/libs/utils/deviceshell.cpp +++ b/src/libs/utils/deviceshell.cpp @@ -185,7 +185,7 @@ Result<> DeviceShell::start() if (!m_shellProcess->waitForStarted()) { closeShellProcess(); - return make_unexpected(Tr::tr("The process failed to start.")); + return ResultError(Tr::tr("The process failed to start.")); } auto installResult = installShellScript(); @@ -219,7 +219,7 @@ Result<> DeviceShell::start() const QString stdErr = m_shellProcess->readAllStandardError(); m_shellProcess.reset(); - return make_unexpected(Tr::tr("Failed to install shell script: %1\n%2") + return ResultError(Tr::tr("Failed to install shell script: %1\n%2") .arg(installResult.error()) .arg(stdErr)); }, @@ -235,14 +235,14 @@ Result DeviceShell::checkCommand(const QByteArray &command) m_shellProcess->writeRaw(checkCmd); if (!m_shellProcess->waitForReadyRead()) { - return make_unexpected( + return ResultError( Tr::tr("Timeout while trying to check for %1.").arg(QString::fromUtf8(command))); } QByteArray out = m_shellProcess->readAllRawStandardOutput(); if (out.contains("")) { m_shellScriptState = State::Failed; m_missingFeatures.append(QString::fromUtf8(command)); - return make_unexpected( + return ResultError( Tr::tr("Command \"%1\" was not found.").arg(QString::fromUtf8(command))); } diff --git a/src/libs/utils/externalterminalprocessimpl.cpp b/src/libs/utils/externalterminalprocessimpl.cpp index 8a640750f26..71c5f351d57 100644 --- a/src/libs/utils/externalterminalprocessimpl.cpp +++ b/src/libs/utils/externalterminalprocessimpl.cpp @@ -121,7 +121,7 @@ Result ProcessStubCreator::startStubProcess(const ProcessSetupData &setu QTemporaryFile shFile; shFile.setAutoRemove(false); QTC_ASSERT(shFile.open(), - return make_unexpected(Tr::tr("Failed to open temporary script file."))); + return ResultError(Tr::tr("Failed to open temporary script file."))); const QString shScript = QString("cd '%1'\n%2\nclear\n'%3' %4\nrm '%5'\n") .arg(setupData.m_workingDirectory.nativePath()) @@ -148,7 +148,7 @@ Result ProcessStubCreator::startStubProcess(const ProcessSetupData &setu process->start(); if (!process->waitForStarted()) { - return make_unexpected( + return ResultError( Tr::tr("Failed to start terminal process: \"%1\".").arg(process->errorString())); } @@ -196,7 +196,7 @@ Result ProcessStubCreator::startStubProcess(const ProcessSetupData &setu process->start(); process->waitForStarted(); if (process->error() != QProcess::UnknownError) { - return make_unexpected( + return ResultError( Tr::tr("Failed to start terminal process: \"%1\".").arg(process->errorString())); } diff --git a/src/libs/utils/fancylineedit.cpp b/src/libs/utils/fancylineedit.cpp index c4ed3d3e2a7..47c979bb848 100644 --- a/src/libs/utils/fancylineedit.cpp +++ b/src/libs/utils/fancylineedit.cpp @@ -631,7 +631,7 @@ void FancyLineEdit::validate() if (validates) result = t; else - result = make_unexpected(error); + result = ResultError(error); handleValidationResult(result, t); } diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index f1e45a71273..c4920c89382 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -649,7 +649,7 @@ Result FilePath::tmpDir() const if (!isLocal()) { const Result env = deviceEnvironmentWithError(); if (!env) - return make_unexpected(env.error()); + return ResultError(env.error()); if (env->hasKey("TMPDIR")) return withNewPath(env->value("TMPDIR")).cleanPath(); @@ -660,7 +660,7 @@ Result FilePath::tmpDir() const if (osType() != OsTypeWindows) return withNewPath("/tmp"); - return make_unexpected(QString("Could not find temporary directory on device %1") + return ResultError(QString("Could not find temporary directory on device %1") .arg(displayName())); } @@ -675,7 +675,7 @@ Result FilePath::createTempFile() const if (file.open()) return FilePath::fromString(file.fileName()); - return make_unexpected(QString("Could not create temporary file: %1").arg(file.errorString())); + return ResultError(QString("Could not create temporary file: %1").arg(file.errorString())); } return fileAccess()->createTempFile(*this); @@ -2342,7 +2342,7 @@ Result FilePath::localSource() const return *this; QTC_ASSERT(deviceFileHooks().localSource, - return make_unexpected(Tr::tr("No \"localSource\" device hook set."))); + return ResultError(Tr::tr("No \"localSource\" device hook set."))); return deviceFileHooks().localSource(*this); } @@ -2572,7 +2572,7 @@ Result> TemporaryFilePath::create( { Result result = templatePath.createTempFile(); if (!result) - return make_unexpected(result.error()); + return ResultError(result.error()); return std::unique_ptr(new TemporaryFilePath(templatePath, *result)); } diff --git a/src/libs/utils/filestreamermanager.cpp b/src/libs/utils/filestreamermanager.cpp index 9cdfb15c039..a35c368434d 100644 --- a/src/libs/utils/filestreamermanager.cpp +++ b/src/libs/utils/filestreamermanager.cpp @@ -132,7 +132,7 @@ FileStreamHandle FileStreamerManager::copy(const FilePath &source, const FilePat if (streamer->result() == Tasking::DoneResult::Success) cont({}); else - cont(make_unexpected(Tr::tr("Failed copying file."))); + cont(ResultError(Tr::tr("Failed copying file."))); }; return execute(onSetup, onDone, context); } @@ -156,7 +156,7 @@ FileStreamHandle FileStreamerManager::read(const FilePath &source, QObject *cont if (streamer->result() == Tasking::DoneResult::Success) cont(streamer->readData()); else - cont(make_unexpected(Tr::tr("Failed reading file."))); + cont(ResultError(Tr::tr("Failed reading file."))); }; return execute(onSetup, onDone, context); } @@ -182,7 +182,7 @@ FileStreamHandle FileStreamerManager::write(const FilePath &destination, const Q if (streamer->result() == Tasking::DoneResult::Success) cont(0); // TODO: return write count? else - cont(make_unexpected(Tr::tr("Failed writing file."))); + cont(ResultError(Tr::tr("Failed writing file."))); }; return execute(onSetup, onDone, context); } diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index ce382a77791..54eccbfe0d2 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -835,7 +835,7 @@ Result scratchBufferFilePath(const QString &pattern) QTemporaryFile file(tmp); file.setAutoRemove(false); if (!file.open()) { - return make_unexpected(Tr::tr("Failed to set up scratch buffer in \"%1\".") + return ResultError(Tr::tr("Failed to set up scratch buffer in \"%1\".") .arg(FilePath::fromString(tmp).parentDir().toUserOutput())); } file.close(); diff --git a/src/libs/utils/lua.cpp b/src/libs/utils/lua.cpp index 7d88ec27c10..cb6f9abb134 100644 --- a/src/libs/utils/lua.cpp +++ b/src/libs/utils/lua.cpp @@ -22,7 +22,7 @@ LuaInterface *luaInterface() Result> runScript(const QString &script, const QString &name) { if (!s_luaInterface) - return make_unexpected(Tr::tr("No Lua interface set")); + return ResultError(Tr::tr("No Lua interface set")); return s_luaInterface->runScript(script, name); } diff --git a/src/libs/utils/macroexpander.cpp b/src/libs/utils/macroexpander.cpp index 4f767fec5fa..3b8f4dea4a1 100644 --- a/src/libs/utils/macroexpander.cpp +++ b/src/libs/utils/macroexpander.cpp @@ -415,8 +415,7 @@ QVariant MacroExpander::expandVariant(const QVariant &v) const return v; } -Result MacroExpander::expandProcessArgs( - const QString &argsWithVariables, Utils::OsType osType) const +Result MacroExpander::expandProcessArgs(const QString &argsWithVariables, OsType osType) const { QString result = argsWithVariables; const bool ok = ProcessArgs::expandMacros( @@ -425,7 +424,7 @@ Result MacroExpander::expandProcessArgs( osType); if (!ok) { - return make_unexpected( + return ResultError( Tr::tr("Failed to expand macros in process arguments: %1").arg(argsWithVariables)); } return result; diff --git a/src/libs/utils/osspecificaspects.h b/src/libs/utils/osspecificaspects.h index 410cbe5a79e..3dc705f8872 100644 --- a/src/libs/utils/osspecificaspects.h +++ b/src/libs/utils/osspecificaspects.h @@ -49,7 +49,7 @@ inline Utils::Result osTypeFromString(const QString &string) if (string.compare("other unix", Qt::CaseInsensitive) == 0) return OsTypeOtherUnix; - return Utils::make_unexpected(QString::fromLatin1("Unknown os type: %1").arg(string)); + return Utils::ResultError(QString::fromLatin1("Unknown os type: %1").arg(string)); } inline Utils::Result osArchFromString(const QString &architecture) @@ -65,7 +65,7 @@ inline Utils::Result osArchFromString(const QString &architecture) if (architecture == QLatin1String("arm64") || architecture == QLatin1String("aarch64")) return OsArchArm64; - return Utils::make_unexpected(QString::fromLatin1("Unknown architecture: %1").arg(architecture)); + return Utils::ResultError(QString::fromLatin1("Unknown architecture: %1").arg(architecture)); } namespace OsSpecificAspects { diff --git a/src/libs/utils/pathchooser.cpp b/src/libs/utils/pathchooser.cpp index 5befd12c2b0..a87218839bc 100644 --- a/src/libs/utils/pathchooser.cpp +++ b/src/libs/utils/pathchooser.cpp @@ -539,7 +539,7 @@ static FancyLineEdit::AsyncValidationResult validatePath(FilePath filePath, if (!defaultValue.isEmpty()) { filePath = FilePath::fromUserInput(defaultValue); } else { - return make_unexpected(Tr::tr("The path must not be empty.")); + return ResultError(Tr::tr("The path must not be empty.")); } } @@ -547,57 +547,57 @@ static FancyLineEdit::AsyncValidationResult validatePath(FilePath filePath, switch (kind) { case PathChooser::ExistingDirectory: if (!filePath.exists()) { - return make_unexpected( + return ResultError( Tr::tr("The path \"%1\" does not exist.").arg(filePath.toUserOutput())); } if (!filePath.isDir()) { - return make_unexpected( + return ResultError( Tr::tr("The path \"%1\" is not a directory.").arg(filePath.toUserOutput())); } break; case PathChooser::File: if (!filePath.exists()) { - return make_unexpected( + return ResultError( Tr::tr("The path \"%1\" does not exist.").arg(filePath.toUserOutput())); } if (!filePath.isFile()) { - return make_unexpected( + return ResultError( Tr::tr("The path \"%1\" is not a file.").arg(filePath.toUserOutput())); } break; case PathChooser::SaveFile: if (!filePath.parentDir().exists()) { - return make_unexpected( + return ResultError( Tr::tr("The directory \"%1\" does not exist.").arg(filePath.toUserOutput())); } if (filePath.exists() && filePath.isDir()) { - return make_unexpected( + return ResultError( Tr::tr("The path \"%1\" is not a file.").arg(filePath.toUserOutput())); } break; case PathChooser::ExistingCommand: if (!filePath.exists()) { - return make_unexpected( + return ResultError( Tr::tr("The path \"%1\" does not exist.").arg(filePath.toUserOutput())); } if (!filePath.isExecutableFile()) { - return make_unexpected( + return ResultError( Tr::tr("The path \"%1\" is not an executable file.").arg(filePath.toUserOutput())); } break; case PathChooser::Directory: if (filePath.exists() && !filePath.isDir()) { - return make_unexpected( + return ResultError( Tr::tr("The path \"%1\" is not a directory.").arg(filePath.toUserOutput())); } if (filePath.osType() == OsTypeWindows && !filePath.startsWithDriveLetter() && !filePath.startsWith("\\\\") && !filePath.startsWith("//")) { - return make_unexpected(Tr::tr("Invalid path \"%1\".").arg(filePath.toUserOutput())); + return ResultError(Tr::tr("Invalid path \"%1\".").arg(filePath.toUserOutput())); } break; case PathChooser::Command: if (filePath.exists() && !filePath.isExecutableFile()) { - return make_unexpected(Tr::tr("Cannot execute \"%1\".").arg(filePath.toUserOutput())); + return ResultError(Tr::tr("Cannot execute \"%1\".").arg(filePath.toUserOutput())); } break; @@ -613,14 +613,14 @@ FancyLineEdit::AsyncValidationFunction PathChooser::defaultValidationFunction() return [this](const QString &text) -> FancyLineEdit::AsyncValidationFuture { if (text.isEmpty()) { return QtFuture::makeReadyFuture((Utils::Result( - make_unexpected(Tr::tr("The path must not be empty."))))); + ResultError(Tr::tr("The path must not be empty."))))); } const FilePath expanded = d->expandedPath(FilePath::fromUserInput(text)); if (expanded.isEmpty()) { return QtFuture::makeReadyFuture((Utils::Result( - make_unexpected(Tr::tr("The path \"%1\" expanded to an empty string.") + ResultError(Tr::tr("The path \"%1\" expanded to an empty string.") .arg(expanded.toUserOutput()))))); } diff --git a/src/libs/utils/portlist.cpp b/src/libs/utils/portlist.cpp index a89f4426a92..1301e18ba60 100644 --- a/src/libs/utils/portlist.cpp +++ b/src/libs/utils/portlist.cpp @@ -227,7 +227,7 @@ ExecutableItem portsFromProcessRecipe(const Storage &input, const QString stdErr = process.stdErr(); const QString outputString = stdErr.isEmpty() ? stdErr : Tr::tr("Remote error output was: %1").arg(stdErr); - *output = make_unexpected(Utils::joinStrings({errorString, outputString}, '\n')); + *output = ResultError(Utils::joinStrings({errorString, outputString}, '\n')); } }; return ProcessTask(onSetup, onDone); diff --git a/src/libs/utils/processinfo.cpp b/src/libs/utils/processinfo.cpp index 056336b71cc..11e00e35387 100644 --- a/src/libs/utils/processinfo.cpp +++ b/src/libs/utils/processinfo.cpp @@ -38,11 +38,11 @@ static Result> getLocalProcessesUsingProc(const FilePath &dev { const FilePath procDir = devicePath.withNewPath("/proc"); if (!procDir.exists()) - return make_unexpected(Tr::tr("%1 does not exist").arg(procDir.toUserOutput())); + return ResultError(Tr::tr("%1 does not exist").arg(procDir.toUserOutput())); const FilePath find = devicePath.withNewPath("find").searchInPath(); if (!find.isExecutableFile()) - return make_unexpected(Tr::tr("find is not an existing executable")); + return ResultError(Tr::tr("find is not an existing executable")); static const QString execs = "-exec test -f {}/exe \\; " "-exec test -f {}/cmdline \\; " @@ -63,7 +63,7 @@ static Result> getLocalProcessesUsingProc(const FilePath &dev // We can only check the errorString here. The exit code maybe != 0 if one of the "test"s failed. if (!procProcess.errorString().isEmpty()) { - return make_unexpected(Tr::tr("Failed to run %1: %2") + return ResultError(Tr::tr("Failed to run %1: %2") .arg(cmd.executable().toUserOutput()) .arg(procProcess.errorString())); } @@ -116,12 +116,12 @@ static Result> getLocalProcessDataUsingPs( process.setCommand({ps, {"-e", "-o", "pid," + column}}); process.runBlocking(); if (!process.errorString().isEmpty()) { - return make_unexpected( + return ResultError( Tr::tr("Failed to run %1: %2").arg(ps.toUserOutput()).arg(process.errorString())); } if (process.exitCode() != 0) { - return make_unexpected(Tr::tr("Failed to run %1: %2") + return ResultError(Tr::tr("Failed to run %1: %2") .arg(ps.toUserOutput()) .arg(process.readAllStandardError())); } @@ -144,17 +144,17 @@ static Result> getLocalProcessesUsingPs(const FilePath &devic const FilePath ps = deviceRoot.withNewPath("ps").searchInPath(); if (!ps.isExecutableFile()) - return make_unexpected(Tr::tr("ps is not an existing executable")); + return ResultError(Tr::tr("ps is not an existing executable")); // cmdLines are full command lines, usually with absolute path, // exeNames only the file part of the executable's path. const auto exeNames = getLocalProcessDataUsingPs(ps, "comm"); if (!exeNames) - return make_unexpected(exeNames.error()); + return ResultError(exeNames.error()); const auto cmdLines = getLocalProcessDataUsingPs(ps, "args"); if (!cmdLines) - return make_unexpected(cmdLines.error()); + return ResultError(cmdLines.error()); for (auto it = exeNames->begin(), end = exeNames->end(); it != end; ++it) { const qint64 pid = it.key(); @@ -179,17 +179,17 @@ static Result> getProcessesUsingPidin(const FilePath &deviceR { const FilePath pidin = deviceRoot.withNewPath("pidin").searchInPath(); if (!pidin.isExecutableFile()) - return make_unexpected(Tr::tr("pidin is not an existing executable")); + return ResultError(Tr::tr("pidin is not an existing executable")); Process process; process.setCommand({pidin, {"-F", "%a %A {/%n}"}}); process.runBlocking(); if (process.errorString().isEmpty()) { - return make_unexpected( + return ResultError( Tr::tr("Failed to run %1: %2").arg(pidin.toUserOutput()).arg(process.errorString())); } if (process.exitCode() != 0) - return make_unexpected(process.readAllStandardError()); + return ResultError(process.readAllStandardError()); QList processes; QStringList lines = process.readAllStandardOutput().split(QLatin1Char('\n')); @@ -251,7 +251,7 @@ Result> ProcessInfo::processInfoList(const FilePath &deviceRo pe.dwSize = sizeof(PROCESSENTRY32); HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (snapshot == INVALID_HANDLE_VALUE) { - return make_unexpected( + return ResultError( Tr::tr("Failed to create snapshot: %1").arg(winErrorMessage(GetLastError()))); } diff --git a/src/libs/utils/result.cpp b/src/libs/utils/result.cpp index 3da594431e1..e0e3c8196fb 100644 --- a/src/libs/utils/result.cpp +++ b/src/libs/utils/result.cpp @@ -24,7 +24,7 @@ Result<> makeResult(bool ok, const QString &errorMessage) { if (ok) return ResultOk; - return tl::make_unexpected(errorMessage); + return ResultError(errorMessage); } } // Utils diff --git a/src/libs/utils/store.cpp b/src/libs/utils/store.cpp index 014e8804d66..5d73e85a0ef 100644 --- a/src/libs/utils/store.cpp +++ b/src/libs/utils/store.cpp @@ -157,10 +157,10 @@ Result storeFromJson(const QByteArray &json) QJsonParseError error; QJsonDocument doc = QJsonDocument::fromJson(json, &error); if (error.error != QJsonParseError::NoError) - return make_unexpected(error.errorString()); + return ResultError(error.errorString()); if (!doc.isObject()) - return make_unexpected(QString("Not a valid JSON object.")); + return ResultError(QString("Not a valid JSON object.")); return storeFromMap(doc.toVariant().toMap()); } diff --git a/src/libs/utils/terminalhooks.cpp b/src/libs/utils/terminalhooks.cpp index ae6a45bfa95..b98ee01f929 100644 --- a/src/libs/utils/terminalhooks.cpp +++ b/src/libs/utils/terminalhooks.cpp @@ -19,7 +19,7 @@ Result defaultShellForDevice(const FilePath &deviceRoot) const Result env = deviceRoot.deviceEnvironmentWithError(); if (!env) - return make_unexpected(env.error()); + return ResultError(env.error()); FilePath shell = FilePath::fromUserInput(env->value_or("SHELL", "/bin/sh")); @@ -27,7 +27,7 @@ Result defaultShellForDevice(const FilePath &deviceRoot) shell = env->searchInPath(shell.nativePath()); if (shell.isEmpty()) - return make_unexpected(Tr::tr("Could not find any shell.")); + return ResultError(Tr::tr("Could not find any shell.")); return deviceRoot.withNewMappedPath(shell); } diff --git a/src/libs/utils/terminalinterface.cpp b/src/libs/utils/terminalinterface.cpp index 33e359d8c83..a7cddd382f4 100644 --- a/src/libs/utils/terminalinterface.cpp +++ b/src/libs/utils/terminalinterface.cpp @@ -206,27 +206,27 @@ Result<> TerminalInterface::startStubServer() .arg(QCoreApplication::applicationPid()) .arg(rand()))) return {}; - return make_unexpected(d->stubServer.errorString()); + return ResultError(d->stubServer.errorString()); } // We need to put the socket in a private directory, as some systems simply do not // check the file permissions of sockets. if (!QDir(d->tempDir.path()) .mkdir("socket")) { // QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner - return make_unexpected(msgCannotCreateTempDir(d->tempDir.filePath("socket"), + return ResultError(msgCannotCreateTempDir(d->tempDir.filePath("socket"), QString::fromLocal8Bit(strerror(errno)))); } if (!QFile::setPermissions(d->tempDir.filePath("socket"), QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)) { - return make_unexpected(Tr::tr("Cannot set permissions on temporary directory \"%1\": %2") + return ResultError(Tr::tr("Cannot set permissions on temporary directory \"%1\": %2") .arg(d->tempDir.filePath("socket")) .arg(QString::fromLocal8Bit(strerror(errno)))); } const QString socketPath = d->tempDir.filePath("socket/stub-socket"); if (!d->stubServer.listen(socketPath)) { - return make_unexpected( + return ResultError( Tr::tr("Cannot create socket \"%1\": %2").arg(socketPath, d->stubServer.errorString())); } return {}; diff --git a/src/libs/utils/theme/theme.cpp b/src/libs/utils/theme/theme.cpp index a10394b305d..212edb28031 100644 --- a/src/libs/utils/theme/theme.cpp +++ b/src/libs/utils/theme/theme.cpp @@ -364,7 +364,7 @@ Result Theme::colorToken(const QString &tokenName, bool ok = false; const Color result = static_cast(colorEnum.keyToValue(colorName.toLatin1(), &ok)); if (!ok) - return make_unexpected(QString::fromLatin1("%1 - Color token \"%2\" not found.") + return ResultError(QString::fromLatin1("%1 - Color token \"%2\" not found.") .arg(Q_FUNC_INFO).arg(tokenName)); return result; } diff --git a/src/plugins/android/androidsettingswidget.cpp b/src/plugins/android/androidsettingswidget.cpp index bba80d7f1e6..014d81a62a8 100644 --- a/src/plugins/android/androidsettingswidget.cpp +++ b/src/plugins/android/androidsettingswidget.cpp @@ -114,14 +114,14 @@ enum OpenSslValidation { static Result<> testJavaC(const FilePath &jdkPath) { if (!jdkPath.isReadableDir()) - return make_unexpected(Tr::tr("The selected path does not exist or is not readable.")); + return ResultError(Tr::tr("The selected path does not exist or is not readable.")); const QString javacCommand("javac"); const QString versionParameter("-version"); const FilePath bin = jdkPath / "bin" / (javacCommand + QTC_HOST_EXE_SUFFIX); if (!bin.isExecutableFile()) - return make_unexpected( + return ResultError( Tr::tr("Could not find \"%1\" in the selected path.") .arg(bin.toUserOutput())); @@ -136,20 +136,20 @@ static Result<> testJavaC(const FilePath &jdkPath) const QString stdOut = javacProcess.stdOut().trimmed(); if (javacProcess.exitCode() != 0) - return make_unexpected( + return ResultError( Tr::tr("The selected path does not contain a valid JDK. (%1 failed: %2)") .arg(cmd.toUserOutput(), stdOut)); // We expect "javac " where is "major.minor.patch" const QString outputPrefix = javacCommand + " "; if (!stdOut.startsWith(outputPrefix)) - return make_unexpected(Tr::tr("Unexpected output from \"%1\": %2") + return ResultError(Tr::tr("Unexpected output from \"%1\": %2") .arg(cmd.toUserOutput(), stdOut)); jdkVersion = QVersionNumber::fromString(stdOut.mid(outputPrefix.length()).split('\n').first()); if (jdkVersion.isNull() /* || jdkVersion.majorVersion() != requiredJavaMajorVersion */ ) { - return make_unexpected(Tr::tr("Unsupported JDK version (needs to be %1): %2 (parsed: %3)") + return ResultError(Tr::tr("Unsupported JDK version (needs to be %1): %2 (parsed: %3)") .arg(requiredJavaMajorVersion) .arg(stdOut, jdkVersion.toString())); } @@ -260,7 +260,7 @@ AndroidSettingsWidget::AndroidSettingsWidget() Result<> test = testJavaC(FilePath::fromUserInput(s)); if (!test) { Core::MessageManager::writeSilently(test.error()); - return make_unexpected(test.error()); + return ResultError(test.error()); } return s; }); diff --git a/src/plugins/axivion/axivionplugin.cpp b/src/plugins/axivion/axivionplugin.cpp index 63ffd5d2e6f..a442f94206a 100644 --- a/src/plugins/axivion/axivionplugin.cpp +++ b/src/plugins/axivion/axivionplugin.cpp @@ -892,7 +892,7 @@ Group dashboardInfoRecipe(const DashboardInfoHandler &handler) if (result == DoneWith::Success && dd->m_dashboardInfo) handler(*dd->m_dashboardInfo); else - handler(make_unexpected(QString("Error"))); // TODO: Collect error message in the storage. + handler(ResultError("Error")); // TODO: Collect error message in the storage. }; const Group root { diff --git a/src/plugins/clangformat/clangformatutils.cpp b/src/plugins/clangformat/clangformatutils.cpp index 6790ae590a9..1149e16164f 100644 --- a/src/plugins/clangformat/clangformatutils.cpp +++ b/src/plugins/clangformat/clangformatutils.cpp @@ -332,7 +332,7 @@ Utils::FilePath findConfig(const Utils::FilePath &filePath) return {}; } -ICodeStylePreferences *preferencesForFile(const Utils::FilePath &filePath) +ICodeStylePreferences *preferencesForFile(const FilePath &filePath) { const ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::projectForFile( filePath); @@ -342,7 +342,7 @@ ICodeStylePreferences *preferencesForFile(const Utils::FilePath &filePath) : TextEditor::TextEditorSettings::codeStyle("Cpp")->currentPreferences(); } -Utils::FilePath configForFile(const Utils::FilePath &filePath) +FilePath configForFile(const FilePath &filePath) { if (!getCurrentCustomSettings(filePath)) return findConfig(filePath); @@ -409,16 +409,16 @@ void addQtcStatementMacros(clang::format::FormatStyle &style) } } -Utils::FilePath filePathToCurrentSettings(const TextEditor::ICodeStylePreferences *codeStyle) +FilePath filePathToCurrentSettings(const TextEditor::ICodeStylePreferences *codeStyle) { return Core::ICore::userResourcePath() / "clang-format/" / Utils::FileUtils::fileSystemFriendlyName(codeStyle->displayName()) / QLatin1String(Constants::SETTINGS_FILE_NAME); } -Utils::Result<> parseConfigurationContent(const std::string &fileContent, - clang::format::FormatStyle &style, - bool allowUnknownOptions) +Result<> parseConfigurationContent(const std::string &fileContent, + clang::format::FormatStyle &style, + bool allowUnknownOptions) { llvm::SourceMgr::DiagHandlerTy diagHandler = [](const llvm::SMDiagnostic &diag, void *context) { QString *errorMessage = reinterpret_cast(context); @@ -439,12 +439,11 @@ Utils::Result<> parseConfigurationContent(const std::string &fileContent, errorMessage = errorMessage.trimmed().isEmpty() ? QString::fromStdString(error.message()) : errorMessage; if (error) - return make_unexpected(errorMessage); - return {}; + return ResultError(errorMessage); + return ResultOk; } -Utils::Result<> parseConfigurationFile(const Utils::FilePath &filePath, - clang::format::FormatStyle &style) +Result<> parseConfigurationFile(const FilePath &filePath, clang::format::FormatStyle &style) { return parseConfigurationContent(filePath.fileContents().value_or(QByteArray()).toStdString(), style, true); diff --git a/src/plugins/clangtools/clangtoolslogfilereader.cpp b/src/plugins/clangtools/clangtoolslogfilereader.cpp index 49cec0ed8a5..b59461932ee 100644 --- a/src/plugins/clangtools/clangtoolslogfilereader.cpp +++ b/src/plugins/clangtools/clangtoolslogfilereader.cpp @@ -169,20 +169,20 @@ public: private: const YAML::Node &m_node; FileCache &m_fileCache; - Utils::FilePath m_filePath; + FilePath m_filePath; const char *m_fileOffsetKey = nullptr; int m_extraOffset = 0; }; } // namespace -void parseDiagnostics(QPromise> &promise, - const Utils::FilePath &logFilePath, +void parseDiagnostics(QPromise> &promise, + const FilePath &logFilePath, const AcceptDiagsFromFilePath &acceptFromFilePath) { - const Utils::Result localFileContents = logFilePath.fileContents(); + const Result localFileContents = logFilePath.fileContents(); if (!localFileContents.has_value()) { - promise.addResult(Utils::make_unexpected(localFileContents.error())); + promise.addResult(ResultError(localFileContents.error())); promise.future().cancel(); return; } diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp index 8f45626d162..e59c34bbf47 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsystem.cpp @@ -418,14 +418,14 @@ static Result insertSnippetSilently(const FilePath &cmakeFile, Constants::CMAKE_EDITOR_ID, Core::EditorManager::DoNotMakeVisible | Core::EditorManager::DoNotChangeCurrentEditor)); if (!editor) { - return make_unexpected("BaseTextEditor cannot be obtained for " + cmakeFile.toUserOutput() + return ResultError("BaseTextEditor cannot be obtained for " + cmakeFile.toUserOutput() + ":" + QString::number(snippetLocation.line) + ":" + QString::number(snippetLocation.column)); } editor->insert(snippetLocation.snippet); editor->editorWidget()->autoIndent(); if (!Core::DocumentManager::saveDocument(editor->document())) - return make_unexpected("Changes to " + cmakeFile.toUserOutput() + " could not be saved."); + return ResultError("Changes to " + cmakeFile.toUserOutput() + " could not be saved."); return true; } diff --git a/src/plugins/coreplugin/icore.cpp b/src/plugins/coreplugin/icore.cpp index a632c95a914..fb663a5527f 100644 --- a/src/plugins/coreplugin/icore.cpp +++ b/src/plugins/coreplugin/icore.cpp @@ -703,7 +703,7 @@ static Result clangBinary( if (!fromPath.isEmpty()) return fromPath; - return make_unexpected(Tr::tr("Could not find %1 executable in %2") + return ResultError(Tr::tr("Could not find %1 executable in %2") .arg(binaryBaseName) .arg(clangBinDirectory.toUserOutput())); } diff --git a/src/plugins/coreplugin/loggingviewer.cpp b/src/plugins/coreplugin/loggingviewer.cpp index bc412ce180f..ce888a51555 100644 --- a/src/plugins/coreplugin/loggingviewer.cpp +++ b/src/plugins/coreplugin/loggingviewer.cpp @@ -127,16 +127,16 @@ struct SavedEntry QtMsgType level{QtFatalMsg}; std::optional> levels; - static Utils::Result fromJson(const QJsonObject &obj) + static Result fromJson(const QJsonObject &obj) { if (!obj.contains("name")) - return Utils::make_unexpected(Tr::tr("Entry is missing a logging category name.")); + return ResultError(Tr::tr("Entry is missing a logging category name.")); SavedEntry result; result.name = obj.value("name").toString(); if (!obj.contains("entry")) - return Utils::make_unexpected(Tr::tr("Entry is missing data.")); + return ResultError(Tr::tr("Entry is missing data.")); auto entry = obj.value("entry").toObject(); if (entry.contains("color")) @@ -145,7 +145,7 @@ struct SavedEntry if (entry.contains("level")) { int lvl = entry.value("level").toInt(0); if (lvl < QtDebugMsg || lvl > QtInfoMsg) - return Utils::make_unexpected(Tr::tr("Invalid level: %1").arg(lvl)); + return ResultError(Tr::tr("Invalid level: %1").arg(lvl)); result.level = static_cast(lvl); } @@ -706,7 +706,7 @@ LoggingViewManagerWidget::LoggingViewManagerWidget(QWidget *parent) if (re.isValid()) return input; - return Utils::make_unexpected( + return ResultError( Tr::tr("Invalid regular expression: %1").arg(re.errorString())); }); }); diff --git a/src/plugins/coreplugin/plugininstallwizard.cpp b/src/plugins/coreplugin/plugininstallwizard.cpp index b2544fbd3f7..f000c9d18bf 100644 --- a/src/plugins/coreplugin/plugininstallwizard.cpp +++ b/src/plugins/coreplugin/plugininstallwizard.cpp @@ -148,7 +148,7 @@ static Result> checkPlugin( const Result<> ok = checkPlugin(spec->get(), update); if (ok) return spec; - return Utils::make_unexpected(ok.error()); + return ResultError(ok.error()); } // Async. Result is set if any issue was found. @@ -156,11 +156,11 @@ void checkContents(QPromise &promise, const FilePath &tempDir, bool { QList plugins = pluginSpecsFromArchive(tempDir); if (plugins.isEmpty()) { - promise.addResult(Utils::make_unexpected(Tr::tr("No plugins found."))); + promise.addResult(ResultError(Tr::tr("No plugins found."))); return; } if (plugins.size() > 1) { - promise.addResult(Utils::make_unexpected(Tr::tr("More than one plugin found."))); + promise.addResult(ResultError(Tr::tr("More than one plugin found."))); qDeleteAll(plugins); return; } @@ -168,7 +168,7 @@ void checkContents(QPromise &promise, const FilePath &tempDir, bool PluginSpec *plugin = plugins.front(); const Result<> ok = checkPlugin(plugin, update); if (!ok) { - promise.addResult(Utils::make_unexpected(ok.error())); + promise.addResult(ResultError(ok.error())); delete plugin; return; } diff --git a/src/plugins/debugger/debuggeritem.cpp b/src/plugins/debugger/debuggeritem.cpp index 01f845c246e..b75deb8637e 100644 --- a/src/plugins/debugger/debuggeritem.cpp +++ b/src/plugins/debugger/debuggeritem.cpp @@ -54,7 +54,7 @@ static Result fetchVersionOutput(const FilePath &executable, Environmen proc.runBlocking(); QString output = proc.allOutput().trimmed(); if (proc.result() != ProcessResult::FinishedWithSuccess) - return make_unexpected(output); + return ResultError(output); return output; } @@ -154,11 +154,11 @@ static Utils::Result extractLldbTechnicalData( binaryName.replace(dapServerSuffix, QString{}); const FilePath lldb = fromExecutable.parentDir() / binaryName; if (!lldb.exists()) { - return make_unexpected(QString{"%1 does not exist alongside %2"} + return ResultError(QString{"%1 does not exist alongside %2"} .arg(lldb.fileNameView(), fromExecutable.toUserOutput())); } if (!lldb.isExecutableFile()) { - return make_unexpected(QString{"%1 exists alongside %2 but is not executable"} + return ResultError(QString{"%1 exists alongside %2 but is not executable"} .arg(lldb.fileNameView(), fromExecutable.toUserOutput())); } @@ -190,8 +190,8 @@ const char DEBUGGER_INFORMATION_WORKINGDIRECTORY[] = "WorkingDirectory"; // DebuggerItem // -------------------------------------------------------------------------- -Utils::Result DebuggerItem::TechnicalData::extract( - const FilePath &fromExecutable, const std::optional &customEnvironment) +Result DebuggerItem::TechnicalData::extract( + const FilePath &fromExecutable, const std::optional &customEnvironment) { Environment env = customEnvironment.value_or(fromExecutable.deviceEnvironment()); DebuggerItem::addAndroidLldbPythonEnv(fromExecutable, env); @@ -212,7 +212,7 @@ Utils::Result DebuggerItem::TechnicalData::extract( WinDLLFileVersion, fromExecutable.absoluteFilePath().path(), &errorMessage); if (!errorMessage.isEmpty()) - return make_unexpected(std::move(errorMessage)); + return ResultError(std::move(errorMessage)); return DebuggerItem::TechnicalData{ .engineType = UvscEngineType, @@ -223,7 +223,7 @@ Utils::Result DebuggerItem::TechnicalData::extract( const Result output = fetchVersionOutput(fromExecutable, env); if (!output) { - return make_unexpected(output.error()); + return ResultError(output.error()); } if (output->contains("gdb")) { @@ -267,7 +267,7 @@ Utils::Result DebuggerItem::TechnicalData::extract( }; } - return make_unexpected( + return ResultError( QString{"Failed to determine debugger engine type from '%1'"}.arg(*output)); } diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index 9d8fa9e91d0..904c7cd4fcf 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -221,12 +221,12 @@ public: Result cmdBridgePath = getCmdBridgePath(); if (!cmdBridgePath) - return make_unexpected(cmdBridgePath.error()); + return ResultError(cmdBridgePath.error()); auto fAccess = std::make_unique(this); if (auto result = updateContainerAccess(); !result) - return make_unexpected(result.error()); + return ResultError(result.error()); Result<> initResult = ResultOk; if (cmdBridgePath->isSameDevice(Docker::Internal::settings().dockerBinaryPath())) { @@ -237,7 +237,7 @@ public: = fAccess->deployAndInit(Core::ICore::libexecPath(), q->rootPath(), q->environment()); } if (!initResult) - return make_unexpected(initResult.error()); + return ResultError(initResult.error()); return fAccess; } @@ -548,7 +548,7 @@ Result DockerDevicePrivate::fetchEnvironment() const envCaptureProcess.setWriteData("printenv\n"); envCaptureProcess.runBlocking(); if (envCaptureProcess.result() != ProcessResult::FinishedWithSuccess) { - return make_unexpected(envCaptureProcess.readAllStandardError()); + return ResultError(envCaptureProcess.readAllStandardError()); } const QStringList envLines = QString::fromUtf8(envCaptureProcess.readAllRawStandardOutput()) .split('\n', Qt::SkipEmptyParts);