From 50979f16062c978e643d58a23d8bf2a9281e3e6e Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Tue, 18 Oct 2022 08:13:12 +0200 Subject: [PATCH] Qbs: Better error messages Provides more concrete error messages if the executable is not set or not executable. Change-Id: I336e9cd10ed6588d77add24af1fd0a9fc9766134 Reviewed-by: Christian Kandeler --- src/plugins/qbsprojectmanager/qbssession.cpp | 17 ++++++++++++++--- src/plugins/qbsprojectmanager/qbssession.h | 9 ++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/plugins/qbsprojectmanager/qbssession.cpp b/src/plugins/qbsprojectmanager/qbssession.cpp index b083cc5cf3d..cf5c86dc1c1 100644 --- a/src/plugins/qbsprojectmanager/qbssession.cpp +++ b/src/plugins/qbsprojectmanager/qbssession.cpp @@ -187,8 +187,12 @@ void QbsSession::initialize() connect(d->packetReader, &PacketReader::packetReceived, this, &QbsSession::handlePacket); d->state = State::Initializing; const FilePath qbsExe = QbsSettings::qbsExecutableFilePath(); - if (qbsExe.isEmpty() || !qbsExe.exists()) { - QTimer::singleShot(0, this, [this] { setError(Error::QbsFailedToStart); }); + if (qbsExe.isEmpty()) { + QTimer::singleShot(0, this, [this] { setError(Error::NoQbsPath); }); + return; + } + if (!qbsExe.isExecutableFile()) { + QTimer::singleShot(0, this, [this] { setError(Error::InvalidQbsExecutable); }); return; } d->qbsProcess->setCommand({qbsExe, {"session"}}); @@ -223,6 +227,12 @@ std::optional QbsSession::lastError() const QString QbsSession::errorString(QbsSession::Error error) { switch (error) { + case Error::NoQbsPath: + return Tr::tr("No qbs executable was found, please set the path in the settings."); + case Error::InvalidQbsExecutable: + return Tr::tr("The qbs executable was not found at the specified path, or it is not " + "executable (\"%1\").") + .arg(QbsSettings::qbsExecutableFilePath().toUserOutput()); case Error::QbsQuit: return Tr::tr("The qbs process quit unexpectedly."); case Error::QbsFailedToStart: @@ -231,7 +241,8 @@ QString QbsSession::errorString(QbsSession::Error error) return Tr::tr("The qbs process sent unexpected data."); case Error::VersionMismatch: return Tr::tr("The qbs API level is not compatible with " - "what %1 expects.").arg(Core::Constants::IDE_DISPLAY_NAME); + "what %1 expects.") + .arg(Core::Constants::IDE_DISPLAY_NAME); } return QString(); // For dumb compilers. } diff --git a/src/plugins/qbsprojectmanager/qbssession.h b/src/plugins/qbsprojectmanager/qbssession.h index 8ad9972d6d8..0452bfdd575 100644 --- a/src/plugins/qbsprojectmanager/qbssession.h +++ b/src/plugins/qbsprojectmanager/qbssession.h @@ -100,7 +100,14 @@ public: ~QbsSession() override; enum class State { Initializing, Active, Inactive }; - enum class Error { QbsFailedToStart, QbsQuit, ProtocolError, VersionMismatch }; + enum class Error { + NoQbsPath, + InvalidQbsExecutable, + QbsFailedToStart, + QbsQuit, + ProtocolError, + VersionMismatch + }; std::optional lastError() const; static QString errorString(Error error);