fix: handle json exception in FileResolvingTask

Also needed to add a call to loop.exit() in FlameInstanceCreationTask so
that it would handle the failure of FileResolvingTask properly

Signed-off-by: Lenny McLennington <lenny@sneed.church>
This commit is contained in:
Lenny McLennington 2022-10-24 18:18:27 +01:00
parent edd650aacd
commit 33634764e9
No known key found for this signature in database
GPG Key ID: F0467078ECA45FCB
3 changed files with 13 additions and 3 deletions

View File

@ -85,7 +85,6 @@ private slots:
private: /* data */
NetJob::Ptr m_filesNetJob;
shared_qobject_ptr<Flame::FileResolvingTask> m_modIdResolver;
QUrl m_sourceUrl;
QString m_archivePath;
bool m_downloadRequired = false;

View File

@ -41,7 +41,17 @@ void Flame::FileResolvingTask::netJobFinished()
// job to check modrinth for blocked projects
auto job = new NetJob("Modrinth check", m_network);
blockedProjects = QMap<File *,QByteArray *>();
auto doc = Json::requireDocument(*result);
QJsonDocument doc;
try {
doc = Json::requireDocument(*result);
}
catch (const JSONValidationError &e) {
qDebug() << "Flame::FileResolvingTask: Json Validation error: " << e.what();
emitFailed(e.what());
return;
}
auto array = Json::requireArray(doc.object()["data"]);
for (QJsonValueRef file : array) {
auto fileid = Json::requireInteger(Json::requireObject(file)["id"]);

View File

@ -335,9 +335,10 @@ bool FlameCreationTask::createInstance()
m_mod_id_resolver = new Flame::FileResolvingTask(APPLICATION->network(), m_pack);
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::succeeded, this, [this, &loop] { idResolverSucceeded(loop); });
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::failed, [&](QString reason) {
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::failed, [this, &loop](QString reason) {
m_mod_id_resolver.reset();
setError(tr("Unable to resolve mod IDs:\n") + reason);
loop.exit();
});
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::progress, this, &FlameCreationTask::setProgress);
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::status, this, &FlameCreationTask::setStatus);