Skip to content

Commit

Permalink
[ssucli] Improve warnings when D-Bus is unavailable. Contribute to JB…
Browse files Browse the repository at this point in the history
…#30284
  • Loading branch information
martyone committed May 11, 2017
1 parent 253ffd6 commit a3a07a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 16 additions & 9 deletions ssucli/ssucli.cpp
Expand Up @@ -99,7 +99,7 @@ void SsuCli::optFlavour(QStringList opt)
QDBusPendingReply<> reply = ssuProxy->setFlavour(opt.at(2));
reply.waitForFinished();
if (reply.isError()) {
qerr << "DBus call failed, falling back to libssu" << endl;
qerr << fallingBackToDirectUse(reply.error()) << endl;
ssu.setFlavour(opt.at(2));

SsuRepoManager repoManager;
Expand Down Expand Up @@ -156,7 +156,7 @@ void SsuCli::optMode(QStringList opt)
QDBusPendingReply<> reply = ssuProxy->setDeviceMode(opt.at(2).toInt());
reply.waitForFinished();
if (reply.isError()) {
qerr << "DBus call failed, falling back to libssu" << endl;
qerr << fallingBackToDirectUse(reply.error()) << endl;
ssu.setDeviceMode(Ssu::DeviceModeFlags(opt.at(2).toInt()));

SsuRepoManager repoManager;
Expand Down Expand Up @@ -193,7 +193,7 @@ void SsuCli::optModifyRepo(enum Actions action, QStringList opt)
QDBusPendingReply<> reply = ssuProxy->modifyRepo(action, opt.at(2));
reply.waitForFinished();
if (reply.isError()) {
qerr << "DBus call failed, falling back to libssu" << endl;
qerr << fallingBackToDirectUse(reply.error()) << endl;

switch (action) {
case Add:
Expand Down Expand Up @@ -235,7 +235,7 @@ void SsuCli::optModifyRepo(enum Actions action, QStringList opt)
QDBusPendingReply<> reply = ssuProxy->addRepo(repo, url);
reply.waitForFinished();
if (reply.isError()) {
qerr << "DBus call failed, falling back to libssu" << endl;
qerr << fallingBackToDirectUse(reply.error()) << endl;
repoManager.add(repo, url);
repoManager.update();
uidWarning();
Expand Down Expand Up @@ -278,8 +278,7 @@ void SsuCli::optRegister(QStringList opt)
QDBusPendingReply<> reply = ssuProxy->registerDevice(username, password);
reply.waitForFinished();
if (reply.isError()) {
qerr << "DBus call failed, falling back to libssu" << endl;
qerr << reply.error().message() << endl;
qerr << fallingBackToDirectUse(reply.error()) << endl;
ssu.sendRegistration(username, password);
}

Expand All @@ -303,7 +302,7 @@ void SsuCli::optRelease(QStringList opt)
QDBusPendingReply<> reply = ssuProxy->setRelease(opt.at(2), false);
reply.waitForFinished();
if (reply.isError()) {
qerr << "DBus call failed, falling back to libssu" << endl;
qerr << fallingBackToDirectUse(reply.error()) << endl;
ssu.setRelease(opt.at(2));

SsuRepoManager repoManager;
Expand All @@ -324,7 +323,7 @@ void SsuCli::optRelease(QStringList opt)
QDBusPendingReply<> reply = ssuProxy->setRelease(opt.at(3), true);
reply.waitForFinished();
if (reply.isError()) {
qerr << "DBus call failed, falling back to libssu" << endl;
qerr << fallingBackToDirectUse(reply.error()) << endl;
ssu.setRelease(opt.at(3), true);

SsuRepoManager repoManager;
Expand Down Expand Up @@ -594,7 +593,7 @@ void SsuCli::optUpdateRepos(QStringList opt)
QDBusPendingReply<> reply = ssuProxy->updateRepos();
reply.waitForFinished();
if (reply.isError()) {
qerr << "DBus call failed, falling back to libssu" << endl;
qerr << fallingBackToDirectUse(reply.error()) << endl;
SsuRepoManager repoManager;
repoManager.update();
uidWarning();
Expand Down Expand Up @@ -738,3 +737,11 @@ void SsuCli::usage(QString message)
qout.flush();
QCoreApplication::exit(1);
}

QString SsuCli::fallingBackToDirectUse(const QDBusError &reason) const
{
if (reason.type() == QDBusError::Disconnected)
return QStringLiteral("DBus unavailable, falling back to libssu");
else
return QStringLiteral("WARNING: DBus call failed, falling back to libssu: ") + reason.message();
}
2 changes: 2 additions & 0 deletions ssucli/ssucli.h
Expand Up @@ -78,6 +78,8 @@ public slots:
UserError
};

QString fallingBackToDirectUse(const QDBusError &error) const;

private slots:
void handleResponse();
void handleDBusResponse();
Expand Down

0 comments on commit a3a07a7

Please sign in to comment.