From 0d6575da157130aa378f2d15e831d749861427fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 6 Apr 2023 21:38:12 +0200 Subject: [PATCH] gui: improved error message when project import fails --- gui/mainwindow.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index e3f3631f3..6b0aab0db 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1687,7 +1687,38 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const bool check prjfile = inf.canonicalPath() + '/' + projectFile->getImportProject(); } try { - p.import(prjfile.toStdString()); + + const ImportProject::Type result = p.import(prjfile.toStdString()); + + QString errorMessage; + switch (result) { + case ImportProject::Type::COMPILE_DB: + case ImportProject::Type::VS_SLN: + case ImportProject::Type::VS_VCXPROJ: + case ImportProject::Type::BORLAND: + case ImportProject::Type::CPPCHECK_GUI: + // Loading was successful + break; + case ImportProject::Type::MISSING: + errorMessage = tr("Failed to open file"); + break; + case ImportProject::Type::UNKNOWN: + errorMessage = tr("Unknown project file format"); + break; + case ImportProject::Type::FAILURE: + errorMessage = tr("Failed to import project file"); + break; + } + + if (!errorMessage.isEmpty()) { + QMessageBox msg(QMessageBox::Critical, + tr("Cppcheck"), + tr("Failed to import '%1': %2\n\nAnalysis is stopped.").arg(prjfile).arg(errorMessage), + QMessageBox::Ok, + this); + msg.exec(); + return; + } } catch (InternalError &e) { QMessageBox msg(QMessageBox::Critical, tr("Cppcheck"),