Git commit f8a14b0beeeca0fc8ad267ee424d95c9ad4f1bd6 by Konstantinos Smanis. Committed on 25/10/2013 at 09:46. Pushed by ksmanis into branch 'master'. Assign error codes for a more detailed error reporting. M +10 -4 src/helper/helper.cpp M +24 -19 src/kcm_grub2.cpp http://commits.kde.org/kcm-grub2/f8a14b0beeeca0fc8ad267ee424d95c9ad4f1bd6 diff --git a/src/helper/helper.cpp b/src/helper/helper.cpp index 4cfdeda..a68c207 100644 --- a/src/helper/helper.cpp +++ b/src/helper/helper.cpp @@ -63,6 +63,7 @@ ActionReply Helper::executeCommand(const QStringList &com= mand) reply =3D ActionReply::HelperErrorReply; reply.setErrorCode(exitCode); } + reply.addData(QLatin1String("isProcessReply"), true); reply.addData(QLatin1String("command"), command); reply.addData(QLatin1String("output"), process.readAll()); return reply; @@ -104,17 +105,20 @@ ActionReply Helper::defaults(QVariantMap args) = if (!QFile::exists(originalConfigFileName)) { reply =3D ActionReply::HelperErrorReply; - reply.addData(QLatin1String("errorDescription"), i18nc("@info", "O= riginal configuration file %1 does not exist.", origin= alConfigFileName)); + reply.setErrorCode(1); + reply.addData(QLatin1String("errorDescription"), i18n("Original co= nfiguration file %1 does not exist.", originalConfigFi= leName)); return reply; } if (!QFile::remove(configFileName)) { reply =3D ActionReply::HelperErrorReply; - reply.addData(QLatin1String("errorDescription"), i18nc("@info", "C= annot remove current configuration file %1.", configFi= leName)); + reply.setErrorCode(2); + reply.addData(QLatin1String("errorDescription"), i18n("Cannot remo= ve current configuration file %1.", configFileName)); return reply; } if (!QFile::copy(originalConfigFileName, configFileName)) { reply =3D ActionReply::HelperErrorReply; - reply.addData(QLatin1String("errorDescription"), i18nc("@info", "C= annot copy original configuration file %1 to %2.", originalConfigFileName, configFileName)); + reply.setErrorCode(3); + reply.addData(QLatin1String("errorDescription"), i18n("Cannot copy= original configuration file %1 to %2.", originalConfigFileName, configFileName)); return reply; } return reply; @@ -130,7 +134,8 @@ ActionReply Helper::install(QVariantMap args) for (int i =3D 0; QDir(mountPoint =3D QString(QLatin1String("%1/kc= m-grub2-%2")).arg(QDir::tempPath(), QString::number(i))).exists(); i++); if (!QDir().mkpath(mountPoint)) { reply =3D ActionReply::HelperErrorReply; - reply.addData(QLatin1String("errorDescription"), i18nc("@info"= , "Failed to create temporary mount point.")); + reply.setErrorCode(4); + reply.addData(QLatin1String("errorDescription"), i18n("Failed = to create temporary mount point.")); return reply; } ActionReply mountReply =3D executeCommand(QStringList() << QLatin1= String("mount") << partition << mountPoint); @@ -227,6 +232,7 @@ ActionReply Helper::save(QVariantMap args) QFile file(configFileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { reply =3D ActionReply::HelperErrorReply; + reply.setErrorCode(5); reply.addData(QLatin1String("errorDescription"), file.errorString(= )); return reply; } diff --git a/src/kcm_grub2.cpp b/src/kcm_grub2.cpp index 896b2ac..d2f29c8 100644 --- a/src/kcm_grub2.cpp +++ b/src/kcm_grub2.cpp @@ -1116,29 +1116,34 @@ void KCMGRUB2::processReply(ActionReply &reply) return; } = - if (reply.errorCode() =3D=3D 0) { - QLatin1String key("errorDescription"); - if (reply.data().contains(key)) { - reply.setErrorDescription(reply.data().value(key).toString()); - reply.data().remove(key); + //Process error (contains command, output, errorCode, errorMessage, er= rorDescription) + QLatin1String processKey("isProcessReply"); + if (reply.data().contains(processKey) && reply.data().value(processKey= ).toBool()) { + QString errorMessage; + switch (reply.errorCode()) { + case -2: + errorMessage =3D i18nc("@info", "The process could not be star= ted."); + break; + case -1: + errorMessage =3D i18nc("@info", "The process crashed."); + break; + default: + errorMessage =3D QString::fromUtf8(reply.data().value(QLatin1S= tring("output")).toByteArray().constData()); + break; } + reply.addData(QLatin1String("errorMessage"), errorMessage); + reply.setErrorDescription(i18nc("@info", "Command: %1Error code: %2Error message:%3= ", reply.data().value(QLatin1String("command")).toStringList().jo= in(QLatin1String(" ")), reply.errorCode(), errorMessage)); return; } = - QString errorMessage; - switch (reply.errorCode()) { - case -2: - errorMessage =3D i18nc("@info", "The process could not be started.= "); - break; - case -1: - errorMessage =3D i18nc("@info", "The process crashed."); - break; - default: - errorMessage =3D QString::fromUtf8(reply.data().value(QLatin1Strin= g("output")).toByteArray().constData()); - break; - } - reply.addData(QLatin1String("errorMessage"), errorMessage); - reply.setErrorDescription(i18nc("@info", "Command: %1Error code: %2Error message:%3", reply.data().value(QLatin1String("command")).toStringList().join(Q= Latin1String(" ")), reply.errorCode(), errorMessage)); + //Simple error (contains errorCode, errorMessage, errorDescription) + QLatin1String errorKey("errorDescription"); + if (reply.data().contains(errorKey)) { + QString errorMessage =3D reply.data().value(errorKey).toString(); + reply.addData(QLatin1String("errorMessage"), errorMessage); + reply.setErrorDescription(i18nc("@info", "Error code: %1Error message: %2", reply.errorCode(), errorMe= ssage)); + reply.data().remove(errorKey); + } } QString KCMGRUB2::parseTitle(const QString &line) {