[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kcm-grub2] src: Assign error codes for a more detailed error reporting.
From: Konstantinos Smanis <konstantinos.smanis () gmail ! com>
Date: 2013-10-25 9:47:13
Message-ID: E1VZdz7-0007JN-OC () scm ! kde ! org
[Download RAW message or body]
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 &command)
reply = 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 = ActionReply::HelperErrorReply;
- reply.addData(QLatin1String("errorDescription"), i18nc("@info", "Original \
configuration file <filename>%1</filename> does not exist.", \
originalConfigFileName)); + reply.setErrorCode(1);
+ reply.addData(QLatin1String("errorDescription"), i18n("Original \
configuration file <filename>%1</filename> does not exist.", \
originalConfigFileName)); return reply;
}
if (!QFile::remove(configFileName)) {
reply = ActionReply::HelperErrorReply;
- reply.addData(QLatin1String("errorDescription"), i18nc("@info", "Cannot \
remove current configuration file <filename>%1</filename>.", configFileName)); + \
reply.setErrorCode(2); + reply.addData(QLatin1String("errorDescription"), \
i18n("Cannot remove current configuration file <filename>%1</filename>.", \
configFileName)); return reply;
}
if (!QFile::copy(originalConfigFileName, configFileName)) {
reply = ActionReply::HelperErrorReply;
- reply.addData(QLatin1String("errorDescription"), i18nc("@info", "Cannot copy \
original configuration file <filename>%1</filename> to <filename>%2</filename>.", \
originalConfigFileName, configFileName)); + reply.setErrorCode(3);
+ reply.addData(QLatin1String("errorDescription"), i18n("Cannot copy original \
configuration file <filename>%1</filename> to <filename>%2</filename>.", \
originalConfigFileName, configFileName)); return reply;
}
return reply;
@@ -130,7 +134,8 @@ ActionReply Helper::install(QVariantMap args)
for (int i = 0; QDir(mountPoint = \
QString(QLatin1String("%1/kcm-grub2-%2")).arg(QDir::tempPath(), \
QString::number(i))).exists(); i++); if (!QDir().mkpath(mountPoint)) {
reply = 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 = executeCommand(QStringList() << \
QLatin1String("mount") << partition << mountPoint); @@ -227,6 +232,7 @@ ActionReply \
Helper::save(QVariantMap args) QFile file(configFileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
reply = 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() == 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, \
errorDescription) + QLatin1String processKey("isProcessReply");
+ if (reply.data().contains(processKey) && \
reply.data().value(processKey).toBool()) { + QString errorMessage;
+ switch (reply.errorCode()) {
+ case -2:
+ errorMessage = i18nc("@info", "The process could not be started.");
+ break;
+ case -1:
+ errorMessage = i18nc("@info", "The process crashed.");
+ break;
+ default:
+ errorMessage = \
QString::fromUtf8(reply.data().value(QLatin1String("output")).toByteArray().constData());
+ break;
}
+ reply.addData(QLatin1String("errorMessage"), errorMessage);
+ reply.setErrorDescription(i18nc("@info", "Command: \
<command>%1</command><nl/>Error code: <numid>%2</numid><nl/>Error \
message:<nl/><message>%3</message>", \
reply.data().value(QLatin1String("command")).toStringList().join(QLatin1String(" ")), \
reply.errorCode(), errorMessage)); return;
}
- QString errorMessage;
- switch (reply.errorCode()) {
- case -2:
- errorMessage = i18nc("@info", "The process could not be started.");
- break;
- case -1:
- errorMessage = i18nc("@info", "The process crashed.");
- break;
- default:
- errorMessage = \
QString::fromUtf8(reply.data().value(QLatin1String("output")).toByteArray().constData());
- break;
- }
- reply.addData(QLatin1String("errorMessage"), errorMessage);
- reply.setErrorDescription(i18nc("@info", "Command: \
<command>%1</command><nl/>Error code: <numid>%2</numid><nl/>Error \
message:<nl/><message>%3</message>", \
reply.data().value(QLatin1String("command")).toStringList().join(QLatin1String(" ")), \
reply.errorCode(), errorMessage)); + //Simple error (contains errorCode, \
errorMessage, errorDescription) + QLatin1String errorKey("errorDescription");
+ if (reply.data().contains(errorKey)) {
+ QString errorMessage = reply.data().value(errorKey).toString();
+ reply.addData(QLatin1String("errorMessage"), errorMessage);
+ reply.setErrorDescription(i18nc("@info", "Error code: \
<numid>%1</numid><nl/>Error message: <message>%2</message>", reply.errorCode(), \
errorMessage)); + reply.data().remove(errorKey);
+ }
}
QString KCMGRUB2::parseTitle(const QString &line)
{
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic