From bd5bf555e1167e7088a4391e5cd419dccb39714c Mon Sep 17 00:00:00 2001 From: Byron Luk Date: Mon, 23 Aug 2021 08:01:00 -0700 Subject: [PATCH] add more detailed error handling if profiling data does not have any React marks (#22157) Co-authored-by: Brian Vaughn --- .../__tests__/preprocessData-test.internal.js | 23 +++++++++++++++++++ .../src/import-worker/preprocessData.js | 14 +++++++++++ 2 files changed, 37 insertions(+) diff --git a/packages/react-devtools-scheduling-profiler/src/import-worker/__tests__/preprocessData-test.internal.js b/packages/react-devtools-scheduling-profiler/src/import-worker/__tests__/preprocessData-test.internal.js index 3481068f471b2..3ea5051bcf53e 100644 --- a/packages/react-devtools-scheduling-profiler/src/import-worker/__tests__/preprocessData-test.internal.js +++ b/packages/react-devtools-scheduling-profiler/src/import-worker/__tests__/preprocessData-test.internal.js @@ -234,6 +234,29 @@ describe('preprocessData', () => { await expect(async () => preprocessData([randomSample])).rejects.toThrow(); }); + it('should throw given a timeline without an explicit profiler version mark nor any other React marks', async () => { + const cpuProfilerSample = creactCpuProfilerSample(); + + await expect( + async () => await preprocessData([cpuProfilerSample]), + ).rejects.toThrow( + 'Please provide profiling data from an React application', + ); + }); + + it('should throw given a timeline with React scheduling marks, but without an explicit profiler version mark', async () => { + const cpuProfilerSample = creactCpuProfilerSample(); + const scheduleRenderSample = createUserTimingEntry({ + cat: 'blink.user_timing', + name: '--schedule-render-512-', + }); + const samples = [cpuProfilerSample, scheduleRenderSample]; + + await expect(async () => await preprocessData(samples)).rejects.toThrow( + 'This version of profiling data is not supported', + ); + }); + it('should return empty data given a timeline with no React scheduling profiling marks', async () => { const cpuProfilerSample = creactCpuProfilerSample(); const randomSample = createUserTimingEntry({ diff --git a/packages/react-devtools-scheduling-profiler/src/import-worker/preprocessData.js b/packages/react-devtools-scheduling-profiler/src/import-worker/preprocessData.js index 75cb6f5f442aa..5b1ec5636f07e 100644 --- a/packages/react-devtools-scheduling-profiler/src/import-worker/preprocessData.js +++ b/packages/react-devtools-scheduling-profiler/src/import-worker/preprocessData.js @@ -912,6 +912,20 @@ export default async function preprocessData( timeline.forEach(event => processTimelineEvent(event, profilerData, state)); if (profilerVersion === null) { + if ( + profilerData.schedulingEvents.length === 0 && + profilerData.batchUIDToMeasuresMap.size === 0 + ) { + // No profiler version could indicate data was logged using an older build of React, + // before an explicitly profiler version was included in the logging data. + // But it could also indicate that the website was either not using React, or using a production build. + // The easiest way to check for this case is to see if the data contains any scheduled updates or render work. + throw new InvalidProfileError( + 'No React marks were found in the provided profile.' + + ' Please provide profiling data from an React application running in development or profiling mode.', + ); + } + throw new InvalidProfileError( `This version of profiling data is not supported by the current profiler.`, );