Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/sveltekit/src/vite/sourceMaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,16 @@ export async function makeCustomSentryVitePlugins(
// We need to remove the query string from the source map files that our auto-instrument plugin added
// to proxy the load functions during building.
const mapFile = `${file}.map`;
if (fs.existsSync(mapFile)) {
try {
const mapContent = (await fs.promises.readFile(mapFile, 'utf-8')).toString();
const cleanedMapContent = mapContent.replace(
// oxlint-disable-next-line sdk/no-regexp-constructor -- no user input + escaped anyway
new RegExp(escapeStringForRegex(WRAPPED_MODULE_SUFFIX), 'gm'),
'',
);
await fs.promises.writeFile(mapFile, cleanedMapContent);
} catch {
// Map file doesn't exist, nothing to clean
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overly broad catch silently swallows non-ENOENT errors

Medium Severity

The new catch block silently swallows all errors, not just ENOENT (file not found). If readFile or writeFile fails due to permission errors, disk full, or other I/O issues, the failure is silently ignored. The try/catch block just above (lines 202–211) demonstrates the better pattern already used in this file: it checks whether the error is a known ENOENT and logs unexpected errors when debug is enabled. The same approach would be appropriate here.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix PR missing regression test for the change

Low Severity

This is a fix PR but no regression test was added to verify the race condition fix. The existing test file sourceMaps.test.ts has no tests covering the source map file cleaning logic (the readFile/writeFile path for .map files). A test verifying behavior when the map file doesn't exist — and ideally when other I/O errors occur — would help prevent regressions.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

}
}

Expand Down
Loading