Skip to content

Commit

Permalink
fix: provisional fix for Trace Viewer source 404 (#29192)
Browse files Browse the repository at this point in the history
Motivation: Sometimes the files are not available anymore on the Service
Worker side. The Trace Viewer frontend then falls back to `file?path=`
and uses its response, no matter what the response status is.

This patch checks for the response status code before using its
response.

e.g. microsoft/playwright-dotnet#2775 after
some time / and some other reports.

---------

Signed-off-by: Max Schmitt <[email protected]>
Co-authored-by: Dmitry Gozman <[email protected]>
  • Loading branch information
mxschmitt and dgozman authored Jan 27, 2024
1 parent 5ee7179 commit 36ebdfb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/trace-viewer/src/ui/sourceTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ export const SourceTab: React.FunctionComponent<{
let response = await fetch(`sha1/src@${sha1}.txt`);
if (response.status === 404)
response = await fetch(`file?path=${encodeURIComponent(file)}`);
source.content = await response.text();
if (response.status >= 400)
source.content = `<Unable to read "${file}">`;
else
source.content = await response.text();
} catch {
source.content = `<Unable to read "${file}">`;
}
Expand Down

0 comments on commit 36ebdfb

Please sign in to comment.