From d33845708e9f299536256d583abe68a08ed7634e Mon Sep 17 00:00:00 2001 From: Giacomo Pozzoni Date: Fri, 13 Oct 2023 13:39:38 +0200 Subject: [PATCH 1/2] Fix retrieving error detail in Get-UPABulkImportStatus --- src/Commands/UserProfiles/GetUPABulkImportStatus.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/UserProfiles/GetUPABulkImportStatus.cs b/src/Commands/UserProfiles/GetUPABulkImportStatus.cs index d0f50bcdf..964b4b570 100644 --- a/src/Commands/UserProfiles/GetUPABulkImportStatus.cs +++ b/src/Commands/UserProfiles/GetUPABulkImportStatus.cs @@ -48,7 +48,7 @@ private void GetErrorInfo(ImportProfilePropertiesJobInfo job) { var webUrl = Web.GetWebUrlFromPageUrl(AdminContext, job.LogFolderUri); AdminContext.ExecuteQueryRetry(); - string relativePath = job.LogFolderUri.Replace(webUrl.Value, ""); + string relativePath = new Uri(job.LogFolderUri).LocalPath; var webCtx = AdminContext.Clone(webUrl.Value); if (webCtx.Web.DoesFolderExists(relativePath)) { From 70f3e9344dd8f6e1554b14632672989c33d79f0a Mon Sep 17 00:00:00 2001 From: Giacomo Pozzoni Date: Fri, 13 Oct 2023 14:04:26 +0200 Subject: [PATCH 2/2] Handle exceptions when setting the error message --- .../UserProfiles/GetUPABulkImportStatus.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Commands/UserProfiles/GetUPABulkImportStatus.cs b/src/Commands/UserProfiles/GetUPABulkImportStatus.cs index 964b4b570..5dafb9b6c 100644 --- a/src/Commands/UserProfiles/GetUPABulkImportStatus.cs +++ b/src/Commands/UserProfiles/GetUPABulkImportStatus.cs @@ -60,9 +60,22 @@ private void GetErrorInfo(ImportProfilePropertiesJobInfo job) string message = string.Empty; foreach (var logFile in files) message += "\r\n" + webCtx.Web.GetFileAsString(logFile.ServerRelativeUrl); - job.ErrorMessage = message; + TrySetJobErrorMessage(job, message); } } } + + private void TrySetJobErrorMessage(ImportProfilePropertiesJobInfo job, string message) + { + try + { + job.ErrorMessage = message; + } + catch (ClientRequestException) + { + // Setting the ErrorMessage property to ImportProfilePropertiesJobInfo returned by GetImportProfilePropertyJobs() throws an exception sometimes as the Path is property is null. + // In this case the generic error message with the file location of the log in SPO will be returned. + } + } } } \ No newline at end of file