diff options
author | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2022-12-06 08:59:18 +0100 |
---|---|---|
committer | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2023-01-10 07:12:39 +0000 |
commit | aee7afd50ba8bd91b1191db6f81b1bd3d8a068e1 (patch) | |
tree | af996f86159d9e83fed9b9da39d13e81e83215d8 /src | |
parent | ad2013eee5c2a31fe9ac323cf0beee1c8d7d5440 (diff) | |
download | qt-creator-aee7afd50ba8bd91b1191db6f81b1bd3d8a068e1.tar.gz |
ProjectExplorer: Improve error reporting
Previously anytime a FilePath operation tried to access a device that
does not have a DeviceFileAccess an error message would be thrown.
This patch makes it possible to differentiate between the device not
being found, and the device just not having a DeviceFileAccess
interface.
Also the error message in DeviceFileAccess::exists() was removed as
its not an error to ask if something exists even if it does not.
Change-Id: Ib8c2e08132159d0d97bcd049b59436eb17bdbacd
Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/libs/utils/devicefileaccess.cpp | 1 | ||||
-rw-r--r-- | src/libs/utils/filepath.cpp | 6 | ||||
-rw-r--r-- | src/libs/utils/filepath.h | 2 | ||||
-rw-r--r-- | src/plugins/projectexplorer/devicesupport/devicemanager.cpp | 7 |
4 files changed, 9 insertions, 7 deletions
diff --git a/src/libs/utils/devicefileaccess.cpp b/src/libs/utils/devicefileaccess.cpp index e91f16b711..ed02b444ae 100644 --- a/src/libs/utils/devicefileaccess.cpp +++ b/src/libs/utils/devicefileaccess.cpp @@ -120,7 +120,6 @@ bool DeviceFileAccess::createDirectory(const FilePath &filePath) const bool DeviceFileAccess::exists(const FilePath &filePath) const { Q_UNUSED(filePath) - QTC_CHECK(false); return false; } diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 8fb7fcd47a..7eb95343a6 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -939,9 +939,9 @@ DeviceFileAccess *FilePath::fileAccess() const } static DeviceFileAccess dummy; - DeviceFileAccess *access = s_deviceHooks.fileAccess(*this); - QTC_ASSERT(access, qDebug() << toString(); return &dummy); - return access; + const expected_str<DeviceFileAccess *> access = s_deviceHooks.fileAccess(*this); + QTC_ASSERT_EXPECTED(access, return &dummy); + return *access ? *access : &dummy; } /*! diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index a3da61ce47..05a851d431 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -269,7 +269,7 @@ class QTCREATOR_UTILS_EXPORT DeviceFileHooks public: static DeviceFileHooks &instance(); - std::function<DeviceFileAccess *(const FilePath &)> fileAccess; + std::function<expected_str<DeviceFileAccess *>(const FilePath &)> fileAccess; std::function<QString(const FilePath &)> deviceDisplayName; std::function<bool(const FilePath &, const FilePath &)> ensureReachable; std::function<Environment(const FilePath &)> environment; diff --git a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp index 0ff44bbf34..6448b085b8 100644 --- a/src/plugins/projectexplorer/devicesupport/devicemanager.cpp +++ b/src/plugins/projectexplorer/devicesupport/devicemanager.cpp @@ -422,11 +422,14 @@ DeviceManager::DeviceManager(bool isInstance) : d(std::make_unique<DeviceManager return device->localSource(file); }; - deviceHooks.fileAccess = [](const FilePath &filePath) -> DeviceFileAccess * { + deviceHooks.fileAccess = [](const FilePath &filePath) -> expected_str<DeviceFileAccess *> { if (!filePath.needsDevice()) return DesktopDeviceFileAccess::instance(); auto device = DeviceManager::deviceForPath(filePath); - QTC_ASSERT(device, qDebug() << filePath.toString(); return nullptr); + if (!device) { + return make_unexpected( + QString("No device found for path \"%1\"").arg(filePath.toUserOutput())); + } return device->fileAccess(); }; |