aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJake Petroules <jake.petroules@qt.io>2017-11-12 15:44:59 -0800
committerJake Petroules <jake.petroules@qt.io>2017-11-14 18:18:52 +0000
commitf40667f6fb026fa1747a1e330d6e397bf79435c7 (patch)
tree60edc74e9795915059236ada3c53f9d90fed879c
parentd409f60bdaf935ff78d51683c28018bb8e810891 (diff)
Provide more detailed error output when a Process jsextension fails
This patch prints stdout in addition to stderr, as some programs are not guaranteed to actually print error output to stderr. Additionally, process output is now printed if the QProcess error was 'Crashed', since this means that the process DID start and thus potentially printed some output. Change-Id: I3e513ad30d05fa4e29ea2ab8e1b911b1110d75bd Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--src/lib/corelib/jsextensions/process.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/lib/corelib/jsextensions/process.cpp b/src/lib/corelib/jsextensions/process.cpp
index fd8448132..fed7e57e7 100644
--- a/src/lib/corelib/jsextensions/process.cpp
+++ b/src/lib/corelib/jsextensions/process.cpp
@@ -215,12 +215,18 @@ int Process::exec(const QString &program, const QStringList &arguments, bool thr
m_qProcess->closeWriteChannel();
m_qProcess->waitForFinished(-1);
if (throwOnError) {
- if (m_qProcess->error() != QProcess::UnknownError) {
+ if (m_qProcess->error() != QProcess::UnknownError
+ && m_qProcess->error() != QProcess::Crashed) {
context()->throwError(Tr::tr("Error running '%1': %2")
.arg(program, m_qProcess->errorString()));
- } else if (m_qProcess->exitCode() != 0) {
- QString errorMessage = Tr::tr("Process '%1' finished with exit code %2.")
- .arg(program).arg(m_qProcess->exitCode());
+ } else if (m_qProcess->exitStatus() == QProcess::CrashExit || m_qProcess->exitCode() != 0) {
+ QString errorMessage = m_qProcess->error() == QProcess::Crashed
+ ? Tr::tr("Error running '%1': %2").arg(program, m_qProcess->errorString())
+ : Tr::tr("Process '%1' finished with exit code %2.").arg(program).arg(
+ m_qProcess->exitCode());
+ const QString stdOut = readStdOut();
+ if (!stdOut.isEmpty())
+ errorMessage.append(Tr::tr(" The standard output was:\n")).append(stdOut);
const QString stdErr = readStdErr();
if (!stdErr.isEmpty())
errorMessage.append(Tr::tr(" The standard error output was:\n")).append(stdErr);