add more detailed error handling if profiling data does not have any React marks (#22157)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
Byron Luk committed
Aug 23, 2021 at 08:01 UTC
bd5bf555e1167e7088a4391e5cd419dccb39714c
2 files changed
+37
packages/react-devtools-scheduling-profiler/src/import-worker/__tests__/preprocessData-test.internal.js
+23
@@ -234,6 +234,29 @@ describe('preprocessData', () => {
234
await expect(async () => preprocessData([randomSample])).rejects.toThrow();
235
});
236
237
+ it('should throw given a timeline without an explicit profiler version mark nor any other React marks', async () => {
238
+ const cpuProfilerSample = creactCpuProfilerSample();
239
+
240
+ await expect(
241
+ async () => await preprocessData([cpuProfilerSample]),
242
+ ).rejects.toThrow(
243
+ 'Please provide profiling data from an React application',
244
+ );
245
+ });
246
+
247
+ it('should throw given a timeline with React scheduling marks, but without an explicit profiler version mark', async () => {
248
+ const cpuProfilerSample = creactCpuProfilerSample();
249
+ const scheduleRenderSample = createUserTimingEntry({
250
+ cat: 'blink.user_timing',
251
+ name: '--schedule-render-512-',
252
+ });
253
+ const samples = [cpuProfilerSample, scheduleRenderSample];
254
+
255
+ await expect(async () => await preprocessData(samples)).rejects.toThrow(
256
+ 'This version of profiling data is not supported',
257
+ );
258
+ });
259
+
260
it('should return empty data given a timeline with no React scheduling profiling marks', async () => {
261
const cpuProfilerSample = creactCpuProfilerSample();
262
const randomSample = createUserTimingEntry({
packages/react-devtools-scheduling-profiler/src/import-worker/preprocessData.js
+14
@@ -912,6 +912,20 @@ export default async function preprocessData(
912
timeline.forEach(event => processTimelineEvent(event, profilerData, state));
913
914
if (profilerVersion === null) {
915
+ if (
916
+ profilerData.schedulingEvents.length === 0 &&
917
+ profilerData.batchUIDToMeasuresMap.size === 0
918
+ ) {
919
+ // No profiler version could indicate data was logged using an older build of React,
920
+ // before an explicitly profiler version was included in the logging data.
921
+ // But it could also indicate that the website was either not using React, or using a production build.
922
+ // The easiest way to check for this case is to see if the data contains any scheduled updates or render work.
923
+ throw new InvalidProfileError(
924
+ 'No React marks were found in the provided profile.' +
925
+ ' Please provide profiling data from an React application running in development or profiling mode.',
926
+ );
927
+ }
928
+
929
throw new InvalidProfileError(
930
`This version of profiling data is not supported by the current profiler.`,
931
);