fix(ModUpdater): fail mods individually when there's errors in the JSON
Prevents a single problematic mod from invalidating all the API response. Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
c294c2d1df
commit
9407596b12
@ -289,44 +289,54 @@ Task::Ptr EnsureMetadataTask::modrinthProjectsTask()
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonArray entries;
|
||||
|
||||
try {
|
||||
QJsonArray entries;
|
||||
if (addonIds.size() == 1)
|
||||
entries = { doc.object() };
|
||||
else
|
||||
entries = Json::requireArray(doc);
|
||||
|
||||
for (auto entry : entries) {
|
||||
auto entry_obj = Json::requireObject(entry);
|
||||
|
||||
ModPlatform::IndexedPack pack;
|
||||
Modrinth::loadIndexedPack(pack, entry_obj);
|
||||
|
||||
auto hash = addonIds.find(pack.addonId.toString()).value();
|
||||
|
||||
auto mod_iter = m_mods.find(hash);
|
||||
if (mod_iter == m_mods.end()) {
|
||||
qWarning() << "Invalid project id from the API response.";
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* mod = mod_iter.value();
|
||||
|
||||
try {
|
||||
setStatus(tr("Parsing API response from Modrinth for '%1'...").arg(mod->name()));
|
||||
|
||||
modrinthCallback(pack, m_temp_versions.find(hash).value(), mod);
|
||||
} catch (Json::JsonException& e) {
|
||||
qDebug() << e.cause();
|
||||
qDebug() << entries;
|
||||
|
||||
emitFail(mod);
|
||||
}
|
||||
}
|
||||
} catch (Json::JsonException& e) {
|
||||
qDebug() << e.cause();
|
||||
qDebug() << doc;
|
||||
}
|
||||
|
||||
for (auto entry : entries) {
|
||||
ModPlatform::IndexedPack pack;
|
||||
|
||||
try {
|
||||
auto entry_obj = Json::requireObject(entry);
|
||||
|
||||
Modrinth::loadIndexedPack(pack, entry_obj);
|
||||
} catch (Json::JsonException& e) {
|
||||
qDebug() << e.cause();
|
||||
qDebug() << doc;
|
||||
|
||||
// Skip this entry, since it has problems
|
||||
continue;
|
||||
}
|
||||
|
||||
auto hash = addonIds.find(pack.addonId.toString()).value();
|
||||
|
||||
auto mod_iter = m_mods.find(hash);
|
||||
if (mod_iter == m_mods.end()) {
|
||||
qWarning() << "Invalid project id from the API response.";
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* mod = mod_iter.value();
|
||||
|
||||
try {
|
||||
setStatus(tr("Parsing API response from Modrinth for '%1'...").arg(mod->name()));
|
||||
|
||||
modrinthCallback(pack, m_temp_versions.find(hash).value(), mod);
|
||||
} catch (Json::JsonException& e) {
|
||||
qDebug() << e.cause();
|
||||
qDebug() << entries;
|
||||
|
||||
emitFail(mod);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return proj_task;
|
||||
|
Loading…
Reference in New Issue
Block a user