From b78488b080590ef6ac7f1c33b9a47a8f0e419b4b Mon Sep 17 00:00:00 2001 From: Ondrej Samohel Date: Wed, 4 Nov 2026 16:35:01 +0100 Subject: [PATCH] fix: an unreadable resolve answer is not a confirmed miss getAssetIdent returned (uri, "") both when the server answered that it has no path and when an entry could not be read, because the uri was set before the parsing threw. Callers that cache misses could not tell the two apart. An unreadable entry now returns an empty pair, the same as a transport failure. --- src/AyonCppApi/AyonCppApi.cpp | 28 ++++++++++++++++++++-------- src/AyonCppApi/AyonCppApi.h | 5 +++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/AyonCppApi/AyonCppApi.cpp b/src/AyonCppApi/AyonCppApi.cpp index 7d6b158..78bb48e 100644 --- a/src/AyonCppApi/AyonCppApi.cpp +++ b/src/AyonCppApi/AyonCppApi.cpp @@ -634,22 +634,34 @@ AyonApi::getAssetIdent(const nlohmann::json &uriResolverResponse) { PerfTimer("AyonApi::getAssetIdent"); m_log->info(m_log->key("AyonApi"), "AyonApi::getAssetIdent({})", uriResolverResponse.dump()); - std::pair AssetIdent; if (uriResolverResponse.empty()) { - return AssetIdent; + return {}; } try { - AssetIdent.first = uriResolverResponse.at("uri"); - if (uriResolverResponse.at("entities").size() > 1) { - m_log->warn("Uri resolution returned more than one path: {}", uriResolverResponse.at("entities").dump()); + std::string uri = uriResolverResponse.at("uri").get(); + const nlohmann::json &entities = uriResolverResponse.at("entities"); + if (entities.is_array() && entities.empty()) { + return {std::move(uri), ""}; + } + if (!entities.is_array() || !entities.back().is_object()) { + m_log->warn("asset identification cant be generated {}", uriResolverResponse.dump()); + return {}; + } + if (entities.size() > 1) { + m_log->warn("Uri resolution returned more than one path: {}", entities.dump()); + } + // The server leaves filePath out when the URI names no representation. + const nlohmann::json &entity = entities.back(); + const auto filePath = entity.find("filePath"); + if (filePath == entity.end() || filePath->is_null()) { + return {std::move(uri), ""}; } - AssetIdent.second = rootReplace( - uriResolverResponse.at("entities").at(uriResolverResponse.at("entities").size() - 1).at("filePath")); + return {std::move(uri), rootReplace(filePath->get())}; } catch (const nlohmann::json::exception &e) { m_log->warn("asset identification cant be generated {}", uriResolverResponse.dump()); } - return AssetIdent; + return {}; }; std::string diff --git a/src/AyonCppApi/AyonCppApi.h b/src/AyonCppApi/AyonCppApi.h index 81cf694..79c8d3a 100644 --- a/src/AyonCppApi/AyonCppApi.h +++ b/src/AyonCppApi/AyonCppApi.h @@ -132,6 +132,11 @@ class AyonApi { * @param uriResolverResponse JSON representation of the response from the AYON API resolve endpoint. * @return A pair containing the asset identifier and the machine local file location. */ + /** + * @brief Read one entry of a resolve response. + * @return (uri, path) when resolved; (uri, "") when the server answered that it has no path; + * an empty pair when the entry cannot be read, which says nothing about whether the URI exists. + */ std::pair getAssetIdent(const nlohmann::json &uriResolverResponse); /**