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>
This commit is contained in:
Byron Luk
2021-08-23 11:01:00 -04:00
committed by GitHub
co-authored by Brian Vaughn
parent 0da5ad09db
commit bd5bf555e1
2 changed files with 37 additions and 0 deletions
@@ -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({
@@ -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.`,
);