From 17d3333a8952e3bd2491080081d00a251157e34a Mon Sep 17 00:00:00 2001 From: Lewis Rockliffe Date: Sun, 18 Mar 2018 13:08:28 +0000 Subject: fix error handling in loadState() --- connection.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/connection.cpp b/connection.cpp index 7ba11145..b3f1ceb8 100644 --- a/connection.cpp +++ b/connection.cpp @@ -719,15 +719,18 @@ void Connection::loadState(const QUrl &fromFile) qCDebug(MAIN) << "No state cache file found"; return; } - file.open(QFile::ReadOnly); + if(!file.open(QFile::ReadOnly)) + { + qCWarning(MAIN) << "file " << file.fileName() << "failed to open for read"; + return; + } QByteArray data = file.readAll(); - QJsonParseError e; auto jsonDoc = d->cacheToBinary ? QJsonDocument::fromBinaryData(data) : - QJsonDocument::fromJson(data, &e); - if (e.error != QJsonParseError::NoError) + QJsonDocument::fromJson(data); + if (jsonDoc.isNull()) { - qCWarning(MAIN) << "Cache file not found or broken, discarding"; + qCWarning(MAIN) << "Cache file broken, discarding"; return; } auto actualCacheVersionMajor = -- cgit v1.2.3