From b0771f79e1acf3ebd2f80c7bb620722d8d94064a Mon Sep 17 00:00:00 2001 From: abraunegg Date: Mon, 10 May 2021 08:04:14 +1000 Subject: [PATCH] Fix application crash when SharePoint displayName is being withheld when using --get-O365-drive-id (#1445) * Handle bad ShaprePoint data when the API does not return the expected data points when using those references to display what SharePoint sites are available when using --get-O365-drive-id --- src/sync.d | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/sync.d b/src/sync.d index a406d31b..707cb5d9 100644 --- a/src/sync.d +++ b/src/sync.d @@ -5696,8 +5696,21 @@ final class SyncEngine // Add to siteSearchResults so we can display what we did find string siteSearchResultsEntry; foreach (searchResult; siteQuery["value"].array) { - siteSearchResultsEntry = " * " ~ searchResult["displayName"].str; - siteSearchResults ~= siteSearchResultsEntry; + // We can only add the displayName if it is available + if ("displayName" in searchResult) { + // Use the displayName + siteSearchResultsEntry = " * " ~ searchResult["displayName"].str; + siteSearchResults ~= siteSearchResultsEntry; + } else { + // Add, but indicate displayName unavailable, use id + if ("id" in searchResult) { + siteSearchResultsEntry = " * " ~ "Unknown displayName (Data not provided by API), Site ID: " ~ searchResult["id"].str; + siteSearchResults ~= siteSearchResultsEntry; + } else { + // displayName and id unavailable, display in debug log the entry + log.vdebug("Bad SharePoint Data for site: ", searchResult); + } + } } } } else {