diff options
author | Christian Kandeler <christian.kandeler@digia.com> | 2014-04-10 12:59:32 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@digia.com> | 2014-04-15 12:20:16 +0200 |
commit | 9553d270d18f1f5e0be838a750a8443d8218ff9e (patch) | |
tree | c976749d3d00e54a624421b0a9159af21f8c3646 /src/lib/corelib/buildgraph/processcommandexecutor.cpp | |
parent | 0428fa446c3db835cadf6cbe6e9237bb27073403 (diff) |
Sanitize error/finished handling in executor jobs and command executors.
The classes as they are now specify different signals for signaling
failure and finishing. Some of these error() signals are followed by a
finished() signal, others are not, which is just asking for trouble.
Under certain circumstances there can also be several error() signals
for one and the same process. In fact, there is almost certainly a race
condition there regarding executor job re-use.
This patch changes the design so that there is always exactly one
finished() signal that carries an error status. For some non-fatal
problems that higher-level code cannot sensibly handle, we now log a
warning instead of emitting an error signal.
Change-Id: I9e3df11564e7337ad766ca0d009303367d43c4ec
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Diffstat (limited to 'src/lib/corelib/buildgraph/processcommandexecutor.cpp')
-rw-r--r-- | src/lib/corelib/buildgraph/processcommandexecutor.cpp | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/src/lib/corelib/buildgraph/processcommandexecutor.cpp b/src/lib/corelib/buildgraph/processcommandexecutor.cpp index 6174d25dc..e1733ec40 100644 --- a/src/lib/corelib/buildgraph/processcommandexecutor.cpp +++ b/src/lib/corelib/buildgraph/processcommandexecutor.cpp @@ -133,7 +133,7 @@ void ProcessCommandExecutor::doStart() responseFile.setAutoRemove(false); responseFile.setFileTemplate(QDir::tempPath() + QLatin1String("/qbsresp")); if (!responseFile.open()) { - emit error(ErrorInfo(Tr::tr("Cannot create response file '%1'.") + emit finished(ErrorInfo(Tr::tr("Cannot create response file '%1'.") .arg(responseFile.fileName()))); return; } @@ -175,7 +175,7 @@ QString ProcessCommandExecutor::filterProcessOutput(const QByteArray &_output, + filterFunctionSource + QLatin1String("; f")); if (!filterFunction.isFunction()) { - emit error(ErrorInfo(Tr::tr("Error in filter function: %1.\n%2") + logger().printWarning(ErrorInfo(Tr::tr("Error in filter function: %1.\n%2") .arg(filterFunctionSource, filterFunction.toString()))); return output; } @@ -184,7 +184,7 @@ QString ProcessCommandExecutor::filterProcessOutput(const QByteArray &_output, outputArg.setProperty(0, scriptEngine()->toScriptValue(output)); QScriptValue filteredOutput = filterFunction.call(scriptEngine()->undefinedValue(), outputArg); if (scriptEngine()->hasErrorOrException(filteredOutput)) { - emit error(ErrorInfo(Tr::tr("Error when calling output filter function: %1") + logger().printWarning(ErrorInfo(Tr::tr("Error when calling output filter function: %1") .arg(filteredOutput.toString()))); return output; } @@ -224,32 +224,19 @@ void ProcessCommandExecutor::sendProcessOutput(bool success) void ProcessCommandExecutor::onProcessError() { - sendProcessOutput(false); - removeResponseFile(); - QString errorMessage; - const QString binary = QDir::toNativeSeparators(processCommand()->program()); switch (m_process.error()) { - case QProcess::FailedToStart: - errorMessage = Tr::tr("The process '%1' could not be started: %2"). - arg(binary, m_process.errorString()); + case QProcess::FailedToStart: { + removeResponseFile(); + const QString binary = QDir::toNativeSeparators(processCommand()->program()); + emit finished(ErrorInfo(Tr::tr("The process '%1' could not be started: %2") + .arg(binary, m_process.errorString()))); break; + } case QProcess::Crashed: - errorMessage = Tr::tr("The process '%1' crashed.").arg(binary); - break; - case QProcess::Timedout: - errorMessage = Tr::tr("The process '%1' timed out.").arg(binary); - break; - case QProcess::ReadError: - errorMessage = Tr::tr("Error reading process output from '%1'.").arg(binary); - break; - case QProcess::WriteError: - errorMessage = Tr::tr("Error writing to process '%1'.").arg(binary); - break; + break; // Ignore. Will be handled by onProcessFinished(). default: - errorMessage = Tr::tr("Unknown process error running '%1'.").arg(binary); - break; + logger().qbsWarning() << "QProcess error: " << m_process.errorString(); } - emit error(ErrorInfo(errorMessage)); } void ProcessCommandExecutor::onProcessFinished(int exitCode) @@ -260,13 +247,12 @@ void ProcessCommandExecutor::onProcessFinished(int exitCode) || quint32(exitCode) > quint32(processCommand()->maxExitCode()); sendProcessOutput(!errorOccurred); - if (Q_UNLIKELY(errorOccurred && !crashed)) { // Crash is already reported in onProcessError(). - emit error(ErrorInfo(Tr::tr("Process failed with exit code %1.").arg(exitCode))); - return; - } - - - emit finished(); + if (Q_UNLIKELY(crashed)) + emit finished(ErrorInfo(Tr::tr("Process crashed."))); + else if (Q_UNLIKELY(errorOccurred)) + emit finished(ErrorInfo(Tr::tr("Process failed with exit code %1.").arg(exitCode))); + else + emit finished(); } void ProcessCommandExecutor::removeResponseFile() |