From 312e50d29bba3e6f1cbb3efb60eddc96e6b28e8a Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 17 Jan 2024 14:09:07 +0100 Subject: [PATCH] Process: Introduce exitMessage() helper This is going to be used for tweaked process result. Change-Id: I1e4117dcd6145e4748a55c285b2546974a6e7d00 Reviewed-by: Orgad Shaneh --- src/libs/utils/process.cpp | 23 ++++++++++++++--------- src/libs/utils/process.h | 2 ++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/libs/utils/process.cpp b/src/libs/utils/process.cpp index dede5bb4dc2..15281eba671 100644 --- a/src/libs/utils/process.cpp +++ b/src/libs/utils/process.cpp @@ -1651,26 +1651,31 @@ QString Process::readAllStandardError() return QString::fromUtf8(readAllRawStandardError()); } -QString Process::exitMessage() const +QString Process::exitMessage(const CommandLine &command, ProcessResult result, int exitCode, + int maxHangTimerCount) { - const QString fullCmd = commandLine().toUserOutput(); - switch (result()) { + const QString cmd = command.toUserOutput(); + switch (result) { case ProcessResult::FinishedWithSuccess: - return Tr::tr("The command \"%1\" finished successfully.").arg(fullCmd); + return Tr::tr("The command \"%1\" finished successfully.").arg(cmd); case ProcessResult::FinishedWithError: - return Tr::tr("The command \"%1\" terminated with exit code %2.") - .arg(fullCmd).arg(exitCode()); + return Tr::tr("The command \"%1\" terminated with exit code %2.").arg(cmd).arg(exitCode); case ProcessResult::TerminatedAbnormally: - return Tr::tr("The command \"%1\" terminated abnormally.").arg(fullCmd); + return Tr::tr("The command \"%1\" terminated abnormally.").arg(cmd); case ProcessResult::StartFailed: - return Tr::tr("The command \"%1\" could not be started.").arg(fullCmd); + return Tr::tr("The command \"%1\" could not be started.").arg(cmd); case ProcessResult::Hang: return Tr::tr("The command \"%1\" did not respond within the timeout limit (%2 s).") - .arg(fullCmd).arg(d->m_maxHangTimerCount); + .arg(cmd).arg(maxHangTimerCount); } return {}; } +QString Process::exitMessage() const +{ + return exitMessage(commandLine(), result(), exitCode(), timeoutS()); +} + QByteArray Process::allRawOutput() const { QTC_CHECK(d->m_stdOut.keepRawData); diff --git a/src/libs/utils/process.h b/src/libs/utils/process.h index 3134894b393..6c3c941b5a7 100644 --- a/src/libs/utils/process.h +++ b/src/libs/utils/process.h @@ -182,6 +182,8 @@ public: const QStringList stdOutLines() const; // split, CR removed const QStringList stdErrLines() const; // split, CR removed + static QString exitMessage(const CommandLine &command, ProcessResult result, + int exitCode, int maxHangTimerCount); QString exitMessage() const; QString toStandaloneCommandLine() const;