From 74e1376089bba7bf2a7f00f1f5338dc94eb7c63c Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Fri, 28 Feb 2020 00:02:06 -0800 Subject: [PATCH] Fix the edge case to export and import broken export Summary: This diff fixes the broken export which is being made [here](https://fb.workplace.com/groups/graphqlandroid/permalink/3319822971399628/). In the import there is no client and plugin states. The fact that the validation succeeded on submit button click suggests that the app got disconnected between the click on submit button and the initiation of export, thus exporting the store with no plugin data and client. I have added a validation after exporting the store and before the trace is uploaded. Also in the support request details page, we assumed that client can't be null, relaxed this assumption as the flipper should still open even the above broken export instead of crashing. Reviewed By: mweststrate Differential Revision: D20136295 fbshipit-source-id: f589d01f8ff0ec0b23d53ad5099e11ebbd0930cd --- src/utils/exportData.tsx | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/utils/exportData.tsx b/src/utils/exportData.tsx index 0a216778f..cbfeb9f24 100644 --- a/src/utils/exportData.tsx +++ b/src/utils/exportData.tsx @@ -26,7 +26,7 @@ import { import {default as BaseDevice} from '../devices/BaseDevice'; import {default as ArchivedDevice} from '../devices/ArchivedDevice'; import fs from 'fs'; -import uuid from 'uuid'; +import {v4 as uuidv4} from 'uuid'; import {remote, OpenDialogOptions} from 'electron'; import {readCurrentRevision} from './packageMetadata'; import {tryCatchReportPlatformFailures} from './metrics'; @@ -591,7 +591,7 @@ export async function getStoreExport( clients: client ? [client.toJSON()] : [], devicePlugins, clientPlugins, - salt: uuid.v4(), + salt: uuidv4(), selectedPlugins: state.plugins.selectedPlugins, statusUpdate, }, @@ -605,7 +605,11 @@ export async function exportStore( includeSupportDetails?: boolean, idler?: Idler, statusUpdate?: (msg: string) => void, -): Promise<{serializedString: string; errorArray: Array}> { +): Promise<{ + serializedString: string; + errorArray: Array; + exportStoreData: ExportType | null; +}> { getLogger().track('usage', EXPORT_FLIPPER_TRACE_EVENT); performance.mark(EXPORT_FLIPPER_TRACE_TIME_SERIALIZATION_EVENT); statusUpdate && statusUpdate('Preparing to export Flipper data...'); @@ -647,9 +651,13 @@ export async function exportStore( }); console.error('Export Store Task Failures: ', errorStr); } - return {serializedString, errorArray}; + return {serializedString, errorArray, exportStoreData: exportData}; } else { - return {serializedString: '{}', errorArray: []}; + return { + serializedString: '{}', + errorArray: [], + exportStoreData: exportData, + }; } }