From 4ead0499132bed9e4e067f82334f687d80b3fa4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nidhi=20Tyagi=20=F0=9F=8C=9F=F0=9F=90=87=F0=9F=8C=B4?= =?UTF-8?q?=E2=9D=84=EF=B8=8F?= Date: Thu, 13 Jun 2024 17:49:17 +0530 Subject: [PATCH] Handle multi step form with bad step data --- src/web/client/dal/remoteFetchProvider.ts | 35 ++++++++++++++--------- src/web/client/telemetry/constants.ts | 1 + src/web/client/utilities/commonUtil.ts | 6 ++-- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/web/client/dal/remoteFetchProvider.ts b/src/web/client/dal/remoteFetchProvider.ts index d7c343a8..40c4ec73 100644 --- a/src/web/client/dal/remoteFetchProvider.ts +++ b/src/web/client/dal/remoteFetchProvider.ts @@ -13,6 +13,7 @@ import { isPortalVersionV2, isWebfileContentLoadNeeded, setFileContent, + isNullOrUndefined, } from "../utilities/commonUtil"; import { getCustomRequestURL, getMappingEntityContent, getMetadataInfo, getMappingEntityId, getMimeType, getRequestURL } from "../utilities/urlBuilderUtil"; import { getCommonHeadersForDataverse } from "../../../common/services/AuthenticationProvider"; @@ -333,7 +334,7 @@ async function processDataAndCreateFile( if (fileExtension === undefined) { const expandedContent = getAttributeContent(result, attributePath, entityName, entityId); - if (expandedContent !== Constants.NO_CONTENT) { + if (!isNullOrUndefined(expandedContent)) { await processExpandedData( entityName, expandedContent, @@ -459,7 +460,7 @@ async function createFile( await createVirtualFile( portalsFS, fileUri, - convertContentToUint8Array(fileContent, base64Encoded), + convertContentToUint8Array(fileContent ?? Constants.NO_CONTENT, base64Encoded), entityId, attributePath, encodeAsBase64(entityName, attribute), @@ -576,20 +577,28 @@ export async function preprocessData( // eslint-disable-next-line @typescript-eslint/no-explicit-any data?.forEach((dataItem: any) => { - const webFormSteps = getAttributeContent(dataItem, attributePath, entityType, fetchedFileId as string) as []; + try { + const webFormSteps = getAttributeContent(dataItem, attributePath, entityType, fetchedFileId as string) as []; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const steps: any[] = []; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const steps: any[] = []; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - webFormSteps?.forEach((step: any) => { - const formStepData = advancedFormStepData.get(step); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + !isNullOrUndefined(webFormSteps) && webFormSteps?.forEach((step: any) => { + const formStepData = advancedFormStepData.get(step); - if (formStepData) { - steps.push(formStepData); - } - }); - setFileContent(dataItem, attributePath, steps); + if (formStepData) { + steps.push(formStepData); + } + }); + setFileContent(dataItem, attributePath, steps); + } + catch (error) { + const errorMsg = (error as Error)?.message; + WebExtensionContext.telemetry.sendErrorTelemetry(telemetryEventNames.WEB_EXTENSION_PREPROCESS_DATA_WEBFORM_STEPS_FAILED, + preprocessData.name, + errorMsg); + } }); WebExtensionContext.telemetry.sendInfoTelemetry(telemetryEventNames.WEB_EXTENSION_PREPROCESS_DATA_SUCCESS, { entityType: entityType }); } diff --git a/src/web/client/telemetry/constants.ts b/src/web/client/telemetry/constants.ts index b9a97255..cc0840e9 100644 --- a/src/web/client/telemetry/constants.ts +++ b/src/web/client/telemetry/constants.ts @@ -49,6 +49,7 @@ export enum telemetryEventNames { WEB_EXTENSION_CREATE_ENTITY_FOLDER_FAILED = "webExtensionCreateEntityFolderFailed", WEB_EXTENSION_PREPROCESS_DATA_FAILED = "webExtensionPreprocessDataFailed", WEB_EXTENSION_PREPROCESS_DATA_SUCCESS = "webExtensionPreprocessDataSuccess", + WEB_EXTENSION_PREPROCESS_DATA_WEBFORM_STEPS_FAILED = "webExtensionPreprocessDataWebFormStepsFailed", WEB_EXTENSION_ATTRIBUTE_CONTENT_ERROR = "webExtensionAttributeContentError", WEB_EXTENSION_SET_FILE_CONTENT_ERROR = "webExtensionSetFileContentError", WEB_EXTENSION_FAILED_TO_PREPARE_WORKSPACE = "webExtensionFailedToPrepareWorkspace", diff --git a/src/web/client/utilities/commonUtil.ts b/src/web/client/utilities/commonUtil.ts index acc18a82..184b32e7 100644 --- a/src/web/client/utilities/commonUtil.ts +++ b/src/web/client/utilities/commonUtil.ts @@ -10,7 +10,6 @@ import { CO_PRESENCE_FEATURE_SETTING_NAME, DATA, MULTI_FILE_FEATURE_SETTING_NAME, - NO_CONTENT, STUDIO_PROD_REGION, VERSION_CONTROL_FOR_WEB_EXTENSION_SETTING_NAME, portalSchemaVersion, @@ -63,12 +62,12 @@ export function isExtensionNeededInFileName(entity: string) { // eslint-disable-next-line @typescript-eslint/no-explicit-any export function getAttributeContent(result: any, attributePath: IAttributePath, entityName: string, entityId: string) { - let value = result[attributePath.source] ?? NO_CONTENT; + let value = result[attributePath.source]; try { if (result[attributePath.source] && attributePath.relativePath.length) { value = - JSON.parse(result[attributePath.source])[attributePath.relativePath] ?? NO_CONTENT; + JSON.parse(result[attributePath.source])[attributePath.relativePath]; } } catch (error) { @@ -76,6 +75,7 @@ export function getAttributeContent(result: any, attributePath: IAttributePath, WebExtensionContext.telemetry.sendErrorTelemetry(telemetryEventNames.WEB_EXTENSION_ATTRIBUTE_CONTENT_ERROR, getAttributeContent.name, `For ${entityName} with entityId ${entityId} and attributePath ${JSON.stringify(attributePath)} error: ${errorMsg}`); + return undefined; } return value;