diff --git a/src/lib/data/indexer/TaskExecuteCustomCommands.cpp b/src/lib/data/indexer/TaskExecuteCustomCommands.cpp index a23add9f..06e2b01c 100644 --- a/src/lib/data/indexer/TaskExecuteCustomCommands.cpp +++ b/src/lib/data/indexer/TaskExecuteCustomCommands.cpp @@ -200,13 +200,14 @@ void TaskExecuteCustomCommands::runIndexerCommand(std::shared_ptrbeforeErrorRecording(); std::wstring processOutput; - const int result = utility::executeProcessAndGetExitCode(command, {}, m_projectDirectory, -1, &processOutput); + std::wstring errorMessage; + const int result = utility::executeProcessAndGetExitCode(command, {}, m_projectDirectory, -1, &processOutput, &errorMessage); m_storage->afterErrorRecording(); - if (processOutput.size() > 3 || result != 0) + if (errorMessage.size() > 0 || processOutput.size() > 3 || result != 0) { - if (result == 0) + if (result == 0 && errorMessage.empty()) { std::wstring message = L"Process returned successfully"; if (processOutput.empty()) @@ -224,8 +225,10 @@ void TaskExecuteCustomCommands::runIndexerCommand(std::shared_ptrgetCustomCommand() + L"> returned " + - std::to_wstring(result) + L": " + processOutput, true, false, true).dispatch(); + MessageStatus( + L"command \"" + indexerCommand->getCustomCommand() + L"\" returned code \"" + std::to_wstring(result) + L"\"" + + L" with message \"" + errorMessage + L"\"" + + L" and output \"" + processOutput + L"\".", true, false, true).dispatch(); } } diff --git a/src/lib_gui/utility/utilityApp.cpp b/src/lib_gui/utility/utilityApp.cpp index d33ef77c..93200c69 100644 --- a/src/lib_gui/utility/utilityApp.cpp +++ b/src/lib_gui/utility/utilityApp.cpp @@ -97,10 +97,39 @@ int utility::executeProcessAndGetExitCode( const std::vector& commandArguments, const FilePath& workingDirectory, const int timeout, - std::wstring* processOutput + std::wstring* processOutput, + std::wstring* errorMessage ){ QProcess process; + if (errorMessage != nullptr) + { + QObject::connect(&process, &QProcess::errorOccurred, [errorMessage, commandPath](QProcess::ProcessError error) + { + switch (error) + { + case QProcess::FailedToStart: + *errorMessage = L"File not found or resource error occurred."; + break; + case QProcess::Crashed: + *errorMessage = L"Process crashed."; + break; + case QProcess::Timedout: + *errorMessage = L"Process timed out."; + break; + case QProcess::ReadError: + *errorMessage = L"A read error occurred while executing process."; + break; + case QProcess::WriteError: + *errorMessage = L"A write error occurred while executing process."; + break; + case QProcess::UnknownError: + *errorMessage = L"An unknown error occurred while executing process."; + break; + }; + }); + } + if (!workingDirectory.empty()) { process.setWorkingDirectory(QString::fromStdWString(workingDirectory.wstr())); diff --git a/src/lib_gui/utility/utilityApp.h b/src/lib_gui/utility/utilityApp.h index 864372b2..816510df 100644 --- a/src/lib_gui/utility/utilityApp.h +++ b/src/lib_gui/utility/utilityApp.h @@ -19,7 +19,8 @@ namespace utility const std::vector& commandArguments, const FilePath& workingDirectory = FilePath(), const int timeout = 30000, - std::wstring* processOutput = nullptr + std::wstring* processOutput = nullptr, + std::wstring* errorMessage = nullptr ); void killRunningProcesses();