Skip to content

Commit

Permalink
[urlresolver] Make error cases more userfriendly
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernd Wachter committed May 3, 2013
1 parent 33f2184 commit 9a7a0c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
28 changes: 21 additions & 7 deletions ssuurlresolver/ssuurlresolver.cpp
Expand Up @@ -20,6 +20,16 @@ SsuUrlResolver::SsuUrlResolver(): QObject(){
Qt::QueuedConnection);
}

void SsuUrlResolver::error(QString message){
SsuLog *ssuLog = SsuLog::instance();
ssuLog->print(LOG_WARNING, message);

PluginFrame out("ERROR");
out.setBody(message.toStdString());
out.writeTo(std::cout);
QCoreApplication::exit(1);
}

bool SsuUrlResolver::writeCredentials(QString filePath, QString credentialsScope){
QFile credentialsFile(filePath);
QPair<QString, QString> credentials = ssu.credentials(credentialsScope);
Expand Down Expand Up @@ -53,8 +63,7 @@ void SsuUrlResolver::run(){
PluginFrame in(std::cin);

if (in.headerEmpty()){
// FIXME, do something; we need at least repo header
ssuLog->print(LOG_WARNING, "Received empty header list. Most likely your ssu setup is broken");
error("Received empty header list. Most likely your ssu setup is broken");
}

PluginFrame::HeaderListIterator it;
Expand Down Expand Up @@ -101,8 +110,7 @@ void SsuUrlResolver::run(){
// TODO: figure out if there's better eror handling for
// zypper plugins than 'blow up'
if (ssu.error()){
emit done();
return;
error(ssu.lastError());
}
} else
ssuLog->print(LOG_DEBUG, "Device not registered -- skipping credential update");
Expand Down Expand Up @@ -139,9 +147,15 @@ void SsuUrlResolver::run(){
// is protected, but device is not registered and/or we don't have credentials
ssuLog->print(LOG_INFO, QString("%1 resolved to %2").arg(repo).arg(resolvedUrl));

PluginFrame out("RESOLVEDURL");
out.setBody(resolvedUrl.toStdString());
out.writeTo(std::cout);
if (resolvedUrl.isEmpty()){
error("URL for repository is not set.");
} else if (resolvedUrl.indexOf(QRegExp("[a-z]*://", Qt::CaseInsensitive)) != 0) {
error ("URL for repository is invalid.");
} else {
PluginFrame out("RESOLVEDURL");
out.setBody(resolvedUrl.toStdString());
out.writeTo(std::cout);
}

emit done();
}
1 change: 1 addition & 0 deletions ssuurlresolver/ssuurlresolver.h
Expand Up @@ -53,6 +53,7 @@ class SsuUrlResolver: public QObject {

private:
Ssu ssu;
void error(QString message);
void printJournal(int priority, QString message);
bool writeCredentials(QString filePath, QString credentialsScope);

Expand Down

0 comments on commit 9a7a0c3

Please sign in to comment.