Skip to content

Commit

Permalink
add more detailed error handling if profiling data does not have any …
Browse files Browse the repository at this point in the history
…React marks (facebook#22157)

Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
  • Loading branch information
2 people authored and zhengjitf committed Apr 15, 2022
1 parent ddee304 commit 1f374e2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
);
Expand Down

0 comments on commit 1f374e2

Please sign in to comment.