diff options
| author | Josh Ferrell <josh@vector35.com> | 2024-05-30 22:20:36 -0400 |
|---|---|---|
| committer | Josh Ferrell <josh@vector35.com> | 2024-06-04 13:29:16 -0400 |
| commit | dcd9cc4f62138ef94c6c496fc214045f44e62d4d (patch) | |
| tree | 5fa9e6bcd63256b87ac342e1cbef61a1b540a6a0 /collaboration.cpp | |
| parent | ba88ba867035e7cd32ac967075d6e4df0dcb18d3 (diff) | |
Fix crash in AnalysisMergeConflict::GetPathItem
Diffstat (limited to 'collaboration.cpp')
| -rw-r--r-- | collaboration.cpp | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/collaboration.cpp b/collaboration.cpp index 7b0057c3..b4f7d659 100644 --- a/collaboration.cpp +++ b/collaboration.cpp @@ -2101,15 +2101,65 @@ Ref<Snapshot> AnalysisMergeConflict::GetSecondSnapshot() } -std::any AnalysisMergeConflict::GetPathItem(const std::string& path) +template <> +std::any AnalysisMergeConflict::GetPathItem<std::any>(const std::string& path) { void* val = BNAnalysisMergeConflictGetPathItem(m_object, path.c_str()); if (val == nullptr) - return {}; + throw SyncException(fmt::format("Failed to find merge conflict path item \"{}\"", path)); return *(std::any*)val; } +template <> +uint64_t AnalysisMergeConflict::GetPathItem<uint64_t>(const std::string& path) +{ + std::any anyVal = GetPathItem<std::any>(path); + try + { + return std::any_cast<uint64_t>(anyVal); + } + catch (const std::exception& e) + { + throw SyncException(fmt::format( + "Failed to cast merge conflict path item \"{}\" from \"{}\" to \"{}\": {}", + path, anyVal.type().name(), typeid(uint64_t).name(), e.what() + )); + } +} + + +template <> +std::string AnalysisMergeConflict::GetPathItem<std::string>(const std::string& path) +{ + char* val = BNAnalysisMergeConflictGetPathItemString(m_object, path.c_str()); + if (val == nullptr) + throw SyncException(fmt::format("Failed to find merge conflict path item \"{}\"", path)); + + std::string strVal = val; + BNFreeString(val); + return strVal; +} + + +template <> +nlohmann::json AnalysisMergeConflict::GetPathItem<nlohmann::json>(const std::string& path) +{ + std::any anyVal = GetPathItem<std::any>(path); + try + { + return std::any_cast<nlohmann::json>(anyVal); + } + catch (const std::exception& e) + { + throw SyncException(fmt::format( + "Failed to cast merge conflict path item \"{}\" from \"{}\" to \"{}\": {}", + path, anyVal.type().name(), typeid(nlohmann::json).name(), e.what() + )); + } +} + + bool AnalysisMergeConflict::Success(std::nullopt_t value) { return BNAnalysisMergeConflictSuccess(m_object, nullptr); |
