1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-14 10:24:19 +01:00

Handle subsonic parsing errors instead of using Q_ASSERT

This commit is contained in:
Chocobozzz 2015-05-20 13:50:17 +02:00
parent 0a4de71c37
commit 54771292d6
2 changed files with 46 additions and 12 deletions

View File

@ -264,8 +264,7 @@ void SubsonicService::ReloadDatabaseFinished() {
void SubsonicService::OnLoginStateChanged(
SubsonicService::LoginState newstate) {
// TODO(Alan Briolat): library refresh logic?
if(newstate != LoginState_Loggedin)
library_backend_->DeleteAll();
if (newstate != LoginState_Loggedin) library_backend_->DeleteAll();
}
void SubsonicService::OnPingFinished(QNetworkReply* reply) {
@ -398,7 +397,12 @@ void SubsonicLibraryScanner::OnGetAlbumListFinished(QNetworkReply* reply,
QXmlStreamReader reader(reply);
reader.readNextStartElement();
Q_ASSERT(reader.name() == "subsonic-response");
if (reader.name() != "subsonic-response") {
ParsingError("Not a subsonic-response. Aborting scan.");
return;
}
if (reader.attributes().value("status") != "ok") {
reader.readNextStartElement();
int error = reader.attributes().value("code").toString().toInt();
@ -411,16 +415,25 @@ void SubsonicLibraryScanner::OnGetAlbumListFinished(QNetworkReply* reply,
skip_read_albums = true;
break;
default:
ParsingError("Response status not ok. Aborting scan.");
return;
}
}
int albums_added = 0;
if(skip_read_albums == false) {
if (!skip_read_albums) {
reader.readNextStartElement();
Q_ASSERT(reader.name() == "albumList2");
if (reader.name() != "albumList2") {
ParsingError("albumList2 tag expected. Aborting scan.");
return;
}
while (reader.readNextStartElement()) {
Q_ASSERT(reader.name() == "album");
if (reader.name() != "album") {
ParsingError("album tag expected. Aborting scan.");
return;
}
album_queue_ << reader.attributes().value("id").toString();
albums_added++;
reader.skipCurrentElement();
@ -450,7 +463,12 @@ void SubsonicLibraryScanner::OnGetAlbumFinished(QNetworkReply* reply) {
QXmlStreamReader reader(reply);
reader.readNextStartElement();
Q_ASSERT(reader.name() == "subsonic-response");
if (reader.name() != "subsonic-response") {
ParsingError("Not a subsonic-response. Aborting scan.");
return;
}
if (reader.attributes().value("status") != "ok") {
// TODO(Alan Briolat): error handling
return;
@ -458,12 +476,20 @@ void SubsonicLibraryScanner::OnGetAlbumFinished(QNetworkReply* reply) {
// Read album information
reader.readNextStartElement();
Q_ASSERT(reader.name() == "album");
if (reader.name() != "album") {
ParsingError("album tag expected. Aborting scan.");
return;
}
QString album_artist = reader.attributes().value("artist").toString();
// Read song information
while (reader.readNextStartElement()) {
Q_ASSERT(reader.name() == "song");
if (reader.name() != "song") {
ParsingError("song tag expected. Aborting scan.");
return;
}
Song song;
QString id = reader.attributes().value("id").toString();
song.set_title(reader.attributes().value("title").toString());
@ -519,3 +545,9 @@ void SubsonicLibraryScanner::GetAlbum(const QString& id) {
SLOT(OnGetAlbumFinished(QNetworkReply*)), reply);
pending_requests_.insert(reply);
}
void SubsonicLibraryScanner::ParsingError(const QString& message) {
qLog(Warning) << "Subsonic parsing error: " << message;
scanning_ = false;
emit ScanFinished();
}

View File

@ -167,7 +167,8 @@ class SubsonicLibraryScanner : public QObject {
Q_OBJECT
public:
explicit SubsonicLibraryScanner(SubsonicService* service, QObject* parent = nullptr);
explicit SubsonicLibraryScanner(SubsonicService* service,
QObject* parent = nullptr);
~SubsonicLibraryScanner();
void Scan();
@ -188,6 +189,7 @@ class SubsonicLibraryScanner : public QObject {
private:
void GetAlbumList(int offset);
void GetAlbum(const QString& id);
void ParsingError(const QString& message);
SubsonicService* service_;
bool scanning_;