diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2025-05-03 11:10:41 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2025-05-03 11:10:41 +1000 |
commit | 7bab09614be193ae9b2dc0b5c04d32dbcae6b1b1 (patch) | |
tree | b92c524a0ee02dac496a5159eb7c76504448024f /source/base | |
parent | 81406d70ff42946a0fd878e430eb8dc257ed5719 (diff) |
make troubleshooting errors in json patches easier
Diffstat (limited to 'source/base')
-rw-r--r-- | source/base/StarAssets.cpp | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/source/base/StarAssets.cpp b/source/base/StarAssets.cpp index b6aeab9..3b16137 100644 --- a/source/base/StarAssets.cpp +++ b/source/base/StarAssets.cpp @@ -1055,20 +1055,24 @@ Json Assets::readJson(String const& path) const { if (newResult) result = std::move(newResult); } else { - auto patchJson = inputUtf8Json(patchStream.begin(), patchStream.end(), JsonParseType::Top); - if (patchAssetPath.subPath) - patchJson = patchJson.query(*patchAssetPath.subPath); - if (patchJson.isType(Json::Type::Array)) { - auto patchData = patchJson.toArray(); - try { - result = checkPatchArray(pair.first, patchSource, result, patchData, {}); - } catch (JsonPatchTestFail const& e) { - Logger::debug("Patch test failure from file {} in source: '{}' at '{}'. Caused by: {}", pair.first, patchSource->metadata().value("name", ""), m_assetSourcePaths.getLeft(patchSource), e.what()); - } catch (JsonPatchException const& e) { - Logger::error("Could not apply patch from file {} in source: '{}' at '{}'. Caused by: {}", pair.first, patchSource->metadata().value("name", ""), m_assetSourcePaths.getLeft(patchSource), e.what()); + try { + auto patchJson = inputUtf8Json(patchStream.begin(), patchStream.end(), JsonParseType::Top); + if (patchAssetPath.subPath) + patchJson = patchJson.query(*patchAssetPath.subPath); + if (patchJson.isType(Json::Type::Array)) { + auto patchData = patchJson.toArray(); + try { + result = checkPatchArray(pair.first, patchSource, result, patchData, {}); + } catch (JsonPatchTestFail const& e) { + Logger::debug("Patch test failure from file {} in source: '{}' at '{}'. Caused by: {}", pair.first, patchSource->metadata().value("name", ""), m_assetSourcePaths.getLeft(patchSource), e.what()); + } catch (JsonPatchException const& e) { + Logger::error("Could not apply patch from file {} in source: '{}' at '{}'. Caused by: {}", pair.first, patchSource->metadata().value("name", ""), m_assetSourcePaths.getLeft(patchSource), e.what()); + } + } else if (patchJson.isType(Json::Type::Object)) { + result = jsonMergeNulling(result, patchJson.toObject()); } - } else if (patchJson.isType(Json::Type::Object)) { - result = jsonMergeNulling(result, patchJson.toObject()); + } catch (std::exception const& e) { + throw JsonParsingException(strf("Cannot parse json patch file: {} in source {}", patchBasePath, patchSource->metadata().value("name", "")), e); } } } |