ui: fixed status error may not show up if custom command fails on windows
This commit is contained in:
@@ -200,13 +200,14 @@ void TaskExecuteCustomCommands::runIndexerCommand(std::shared_ptr<IndexerCommand
|
|||||||
m_storage->beforeErrorRecording();
|
m_storage->beforeErrorRecording();
|
||||||
|
|
||||||
std::wstring processOutput;
|
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();
|
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";
|
std::wstring message = L"Process returned successfully";
|
||||||
if (processOutput.empty())
|
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));
|
LOG_ERROR_STREAM(<< "process returned \"" << result << "\" with message:\n" << utility::encodeToUtf8(processOutput));
|
||||||
MessageShowStatus().dispatch();
|
MessageShowStatus().dispatch();
|
||||||
MessageStatus(L"command <" + indexerCommand->getCustomCommand() + L"> returned " +
|
MessageStatus(
|
||||||
std::to_wstring(result) + L": " + processOutput, true, false, true).dispatch();
|
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 std::vector<std::wstring>& commandArguments,
|
||||||
const FilePath& workingDirectory,
|
const FilePath& workingDirectory,
|
||||||
const int timeout,
|
const int timeout,
|
||||||
std::wstring* processOutput
|
std::wstring* processOutput,
|
||||||
|
std::wstring* errorMessage
|
||||||
){
|
){
|
||||||
QProcess process;
|
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())
|
if (!workingDirectory.empty())
|
||||||
{
|
{
|
||||||
process.setWorkingDirectory(QString::fromStdWString(workingDirectory.wstr()));
|
process.setWorkingDirectory(QString::fromStdWString(workingDirectory.wstr()));
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ namespace utility
|
|||||||
const std::vector<std::wstring>& commandArguments,
|
const std::vector<std::wstring>& commandArguments,
|
||||||
const FilePath& workingDirectory = FilePath(),
|
const FilePath& workingDirectory = FilePath(),
|
||||||
const int timeout = 30000,
|
const int timeout = 30000,
|
||||||
std::wstring* processOutput = nullptr
|
std::wstring* processOutput = nullptr,
|
||||||
|
std::wstring* errorMessage = nullptr
|
||||||
);
|
);
|
||||||
|
|
||||||
void killRunningProcesses();
|
void killRunningProcesses();
|
||||||
|
|||||||
Reference in New Issue
Block a user