Skip to content
Permalink
Browse files

ui: fixed status error may not show up if custom command fails on win…

…dows
  • Loading branch information
mlangkabel committed Jan 21, 2019
1 parent 6f0cc61 commit 5dcecdb3bdc6a2ca6b3ae1e5dc6d4aad04aa361b
@@ -200,13 +200,14 @@ void TaskExecuteCustomCommands::runIndexerCommand(std::shared_ptr<IndexerCommand
m_storage->beforeErrorRecording();

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_ptr<IndexerCommand
{
LOG_ERROR_STREAM(<< "process returned \"" << result << "\" with message:\n" << utility::encodeToUtf8(processOutput));
MessageShowStatus().dispatch();
MessageStatus(L"command <" + indexerCommand->getCustomCommand() + 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();
}
}

@@ -97,10 +97,39 @@ int utility::executeProcessAndGetExitCode(
const std::vector<std::wstring>& 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()));
@@ -19,7 +19,8 @@ namespace utility
const std::vector<std::wstring>& commandArguments,
const FilePath& workingDirectory = FilePath(),
const int timeout = 30000,
std::wstring* processOutput = nullptr
std::wstring* processOutput = nullptr,
std::wstring* errorMessage = nullptr
);

void killRunningProcesses();

0 comments on commit 5dcecdb

Please sign in to comment.
You can’t perform that action at this time.