Skip to content

Sentry sourcemap 404#662

Merged
kentcdodds merged 4 commits intomainfrom
cursor/sentry-sourcemap-404-78bf
Feb 22, 2026
Merged

Sentry sourcemap 404#662
kentcdodds merged 4 commits intomainfrom
cursor/sentry-sourcemap-404-78bf

Conversation

@kentcdodds
Copy link
Owner

@kentcdodds kentcdodds commented Feb 22, 2026

Prevent Sentry sourcemap upload failures from silently deleting map files and returning 404 HTML, by making failures fatal and fixing filesToDeleteAfterUpload globs.

The Sentry Vite plugin was configured to delete sourcemap files even if the upload failed, leading to Sentry receiving the application's 404 HTML page when it tried to fetch the maps. This change ensures that upload failures halt the build and that sourcemaps are only deleted after a successful upload.


Open in Web Open in Cursor 


Note

Medium Risk
Build/deploy behavior changes: production builds can now fail on missing/invalid Sentry configuration and sourcemap handling changes may affect artifact size and CI/release pipelines.

Overview
Tightens Sentry behavior across server and build: Sentry initialization is now gated behind a single SHOULD_INIT_SENTRY flag (production + DSN present + not MOCKS=true), preventing Sentry setup during mocked CI/e2e runs.

On the Vite build side, SENTRY_UPLOAD is normalized to a strict boolean and production builds now fail fast when upload is enabled but required Sentry env vars are missing; the Sentry Vite plugin is configured to throw on upload/release errors and the build always generates sourcemaps (build.sourcemap: true) rather than managing deletion via filesToDeleteAfterUpload globs.

Written by Cursor Bugbot for commit e806864. This will update automatically on new commits. Configure here.

Summary by CodeRabbit

  • Bug Fixes

    • Build now fails when Sentry upload/release errors occur, surfacing symbolication issues earlier.
    • Sentry/monitoring is skipped in mock/CI scenarios to avoid unintended initialization.
  • Chores

    • Stronger validation of required Sentry settings in production builds.
    • Standard sourcemap generation enabled and source map cleanup logic simplified.

@cursor
Copy link

cursor bot commented Feb 22, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@coderabbitai
Copy link

coderabbitai bot commented Feb 22, 2026

📝 Walkthrough

Walkthrough

Adds a computed SENTRY_UPLOAD flag and fail-fast validation + errorHandler to the Sentry Vite plugin and enables sourcemap generation in vite.config.ts; centralizes Sentry initialization gating in server/index.ts via a new SHOULD_INIT_SENTRY constant that also respects MOCKS and MODE.

Changes

Cohort / File(s) Summary
Vite + Sentry build config
vite.config.ts
Introduces SENTRY_UPLOAD constant used to conditionally enable the Sentry Vite plugin in production; adds upfront validation that throws if required SENTRY env vars are missing when upload is enabled; adds errorHandler to fail builds on upload/release errors; removes sourcemap deletion logic and enables standard sourcemap generation.
Server Sentry init gating
server/index.ts
Adds SHOULD_INIT_SENTRY constant (requires MODE==='production', non-empty SENTRY_DSN, and MOCKS!=='true') and uses it to gate Sentry/monitoring initialization and environment context setup, preventing init in mock/CI scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Hop-hop-hop, the build machine sings,
I check the keys before upload springs,
Sourcemaps kept, but deleted no more,
Guards at the gate keep errors ashore,
A tidy release, I nibble and spring. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Sentry sourcemap 404' directly relates to the main problem being solved: preventing sourcemap upload failures from causing 404 errors.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cursor/sentry-sourcemap-404-78bf

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kentcdodds
Copy link
Owner Author

@cursoragent our project is open source so I don't think we need to delete source maps

@cursor
Copy link

cursor bot commented Feb 22, 2026

Suggested GitHub reply:

Makes sense — since the repo is OSS, I’ve removed the filesToDeleteAfterUpload behavior so we keep *.map files in the build output (and they’ll be served normally).【F:vite.config.ts†L48-L66】 The PR still keeps the “fail fast” behavior when SENTRY_UPLOAD is enabled, so we don’t silently deploy with Sentry uploads skipped or broken symbolication.【F:vite.config.ts†L14-L32】【F:vite.config.ts†L54-L58】

Summary

  • Stop deleting client sourcemaps; keep fail-fast Sentry upload behavior in vite.config.ts.【F:vite.config.ts†L14-L32】【F:vite.config.ts†L48-L66】

Testing

  • npm run build (ensures the production build still completes end-to-end after the config change).
  • ⚠️ SENTRY_UPLOAD=true COMMIT_SHA=test-sha npm run build (expected failure locally with dummy Sentry creds; verifies we fail fast when upload is enabled but broken/misconfigured, instead of silently continuing).

Open in Web Open in Cursor 

@kentcdodds kentcdodds marked this pull request as ready for review February 22, 2026 17:38
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
vite.config.ts (1)

68-73: ⚠️ Potential issue | 🟠 Major

build.sourcemap is not set — Sentry upload will be a no-op.

By default, Vite's build.sourcemap is false and produces no .map files. The @sentry/vite-plugin does not auto-enable sourcemap generation; its README explicitly requires build: { sourcemap: true } (or 'hidden') as a prerequisite. Without this setting, the plugin has nothing to upload.

For an open-source project, sourcemap: true is appropriate. For closed-source projects, use sourcemap: 'hidden' to upload maps to Sentry without exposing them via sourceMappingURL comments.

🛠️ Proposed fix
 	build: {
 		cssMinify: MODE === 'production',
+		sourcemap: true,
 		rollupOptions: {
 			external: [/node:.*/, 'stream', 'crypto'],
 		},
 	},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@vite.config.ts` around lines 68 - 73, The Vite config's build block (build: {
... }) does not set sourcemap, so `@sentry/vite-plugin` has no maps to upload;
update the build object in vite.config.ts to include build.sourcemap and set it
to true for open-source or 'hidden' for closed-source (keeping existing
cssMinify and rollupOptions intact), i.e., add the sourcemap key alongside
cssMinify and rollupOptions so sourcemaps are generated for Sentry uploads.
🧹 Nitpick comments (2)
vite.config.ts (2)

14-32: Solid fail-fast guard; minor note on the tokenImpliesOrg heuristic.

The sntrys_ prefix check correctly handles new-style Sentry org-scoped tokens that embed org context, making SENTRY_ORG optional. This is a good defensive pattern. Just be aware that if Sentry ever changes this prefix convention the guard silently stops requiring SENTRY_ORG, so it's worth a comment documenting the assumption.

✏️ Suggested clarifying comment
-	const tokenImpliesOrg = Boolean(authToken?.startsWith('sntrys_'))
+	// New-style Sentry auth tokens (prefix "sntrys_") embed the org, so
+	// SENTRY_ORG is not required when using one.
+	const tokenImpliesOrg = Boolean(authToken?.startsWith('sntrys_'))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@vite.config.ts` around lines 14 - 32, Add a short clarifying comment next to
the tokenImpliesOrg heuristic in the SENTRY_UPLOAD/MODE production guard
explaining the assumption that Sentry org-scoped tokens start with "sntrys_" and
that this check makes SENTRY_ORG optional; mention that if Sentry changes the
prefix convention this logic will no longer imply org context and SENTRY_ORG
must be provided. Reference the tokenImpliesOrg const and the surrounding checks
for SENTRY_AUTH_TOKEN, SENTRY_PROJECT and SENTRY_ORG so reviewers understand why
the heuristic exists and when it may need updating.

56-58: Operational trade-off: all Sentry API errors (including transient ones) now block deploys.

Re-throwing unconditionally means a Sentry 503, DNS failure, or rate-limit during upload will halt a production deploy entirely. Consider whether you want to distinguish between configuration/auth errors (should be fatal) and transient network errors (could be retried or warned). The Sentry GitHub discussion shows this is a real-world scenario where teams hit 503s and get their builds blocked.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@vite.config.ts` around lines 56 - 58, The current errorHandler in
vite.config.ts unconditionally re-throws all Sentry upload errors (errorHandler:
(err) => { throw err }), which blocks deploys on transient network or rate-limit
failures; change errorHandler to classify errors (e.g., by HTTP status on
err.status or by error.name/message) and only throw for fatal configuration/auth
errors (401/403, invalid DSN), while for transient errors (5xx, ENOTFOUND,
ETIMEDOUT, rate-limit headers) either perform a limited retry (e.g., 2-3
attempts with backoff) or log a warning via the logger and continue the build.
Add a small helper like isTransientError(err) and use it inside errorHandler to
decide between retry/log-and-continue vs throw so deploys are not blocked by
temporary Sentry outages.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@vite.config.ts`:
- Around line 54-58: The existing comment about the bundler plugin's default
behavior is incorrect; update the comment near the errorHandler option in
vite.config.ts (the errorHandler: (err) => { throw err } block) to state that
currently the `@sentry/vite-plugin` throws by default and that this explicit
errorHandler preserves that throwing behavior as a defensive measure in case the
plugin later changes to log-and-continue; modify the comment text only (leave
the errorHandler implementation unchanged) to accurately describe current
behavior and intent.

---

Outside diff comments:
In `@vite.config.ts`:
- Around line 68-73: The Vite config's build block (build: { ... }) does not set
sourcemap, so `@sentry/vite-plugin` has no maps to upload; update the build object
in vite.config.ts to include build.sourcemap and set it to true for open-source
or 'hidden' for closed-source (keeping existing cssMinify and rollupOptions
intact), i.e., add the sourcemap key alongside cssMinify and rollupOptions so
sourcemaps are generated for Sentry uploads.

---

Nitpick comments:
In `@vite.config.ts`:
- Around line 14-32: Add a short clarifying comment next to the tokenImpliesOrg
heuristic in the SENTRY_UPLOAD/MODE production guard explaining the assumption
that Sentry org-scoped tokens start with "sntrys_" and that this check makes
SENTRY_ORG optional; mention that if Sentry changes the prefix convention this
logic will no longer imply org context and SENTRY_ORG must be provided.
Reference the tokenImpliesOrg const and the surrounding checks for
SENTRY_AUTH_TOKEN, SENTRY_PROJECT and SENTRY_ORG so reviewers understand why the
heuristic exists and when it may need updating.
- Around line 56-58: The current errorHandler in vite.config.ts unconditionally
re-throws all Sentry upload errors (errorHandler: (err) => { throw err }), which
blocks deploys on transient network or rate-limit failures; change errorHandler
to classify errors (e.g., by HTTP status on err.status or by error.name/message)
and only throw for fatal configuration/auth errors (401/403, invalid DSN), while
for transient errors (5xx, ENOTFOUND, ETIMEDOUT, rate-limit headers) either
perform a limited retry (e.g., 2-3 attempts with backoff) or log a warning via
the logger and continue the build. Add a small helper like isTransientError(err)
and use it inside errorHandler to decide between retry/log-and-continue vs throw
so deploys are not blocked by temporary Sentry outages.

Comment on lines +54 to +58
// By default the bundler plugin logs and continues on upload/release
// errors. Fail the build so we don't deploy with broken symbolication.
errorHandler: (err) => {
throw err
},
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

@sentry/vite-plugin errorHandler default behavior documentation latest

💡 Result:

In @sentry/vite-plugin, the errorHandler option is a callback invoked when the plugin hits an error during release creation or sourcemaps upload. By default, no handler is set and the plugin throws the error, which fails/stops the Vite build. If you provide an errorHandler, the build will continue unless your handler itself throws. [1]


Fix inaccurate plugin behavior comment.

The code comment stating "by default the bundler plugin logs and continues on upload/release errors" contradicts the actual documented behaviour of @sentry/vite-plugin. By default (without an errorHandler), the plugin throws an error and stops the build. The explicit errorHandler here is appropriate as a defensive measure to preserve throwing semantics when Sentry switches to log-and-continue defaults in a future SDK version.

✏️ Suggested comment fix
-						// By default the bundler plugin logs and continues on upload/release
-						// errors. Fail the build so we don't deploy with broken symbolication.
+						// Override the default throw behaviour explicitly so this keeps
+						// failing the build even after Sentry switches to log-and-continue
+						// defaults in a future SDK version.
						errorHandler: (err) => {
							throw err
						},
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// By default the bundler plugin logs and continues on upload/release
// errors. Fail the build so we don't deploy with broken symbolication.
errorHandler: (err) => {
throw err
},
// Override the default throw behaviour explicitly so this keeps
// failing the build even after Sentry switches to log-and-continue
// defaults in a future SDK version.
errorHandler: (err) => {
throw err
},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@vite.config.ts` around lines 54 - 58, The existing comment about the bundler
plugin's default behavior is incorrect; update the comment near the errorHandler
option in vite.config.ts (the errorHandler: (err) => { throw err } block) to
state that currently the `@sentry/vite-plugin` throws by default and that this
explicit errorHandler preserves that throwing behavior as a defensive measure in
case the plugin later changes to log-and-continue; modify the comment text only
(leave the errorHandler implementation unchanged) to accurately describe current
behavior and intent.

cursoragent and others added 4 commits February 22, 2026 20:19
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@cursor cursor bot force-pushed the cursor/sentry-sourcemap-404-78bf branch from 562a06d to e806864 Compare February 22, 2026 20:27
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@vite.config.ts`:
- Around line 56-60: Update the inaccurate comment above the errorHandler
option: mention that `@sentry/vite-plugin` currently throws by default when no
errorHandler is provided, and that the explicit errorHandler: (err) => { throw
err } in the configuration is a defensive measure to preserve the throwing
behavior if the plugin's default changes; reference the errorHandler setting to
make intent clear.

@kentcdodds kentcdodds merged commit 8486a00 into main Feb 22, 2026
8 checks passed
@kentcdodds kentcdodds deleted the cursor/sentry-sourcemap-404-78bf branch February 22, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants