Skip to content

fix(static): respond with 404 when a public asset is missing on disk - #4588

Merged
pi0 merged 4 commits into
nitrojs:mainfrom
danielroe:fix/static-enoent
Sep 7, 2026
Merged

pi0 merged 4 commits into
nitrojs:mainfrom
danielroe:fix/static-enoent

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

resolves nuxt/nuxt#33033
resolves nuxt/nuxt#29078

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

when a file can't be read because it can't be read from disk, we can return a 404 instead of a 500 error, which seems wrong.

alternatively, we could always return a 404 when the asset can't be read, if you didn't want to tie this too closely to fs semantics.

... or you may have another better idea!

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe
danielroe requested a review from pi0 as a code owner September 7, 2026 09:30
@vercel

vercel Bot commented Sep 7, 2026

Copy link
Copy Markdown

@danielroe is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 49d77314-528b-4489-9ccc-c51da5991a7f

📥 Commits

Reviewing files that changed from the base of the PR and between 4b07829 and b2eac39.

📒 Files selected for processing (1)
  • src/build/virtual/public-assets.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/build/virtual/public-assets.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The static asset reader now returns undefined for missing files. The handler converts missing results into 404 errors for synchronous and asynchronous readers. Other read errors propagate unchanged. Empty assets remain valid responses.

Changes

Static asset handling

Layer / File(s) Summary
Asset read pipeline
src/build/virtual/public-assets.ts, src/runtime/internal/static.ts
The generated reader returns undefined for ENOENT. The handler validates synchronous and asynchronous results, clears Cache-Control, and throws a 404 for missing data. Other errors propagate unchanged.
Asset read validation
test/unit/public-assets.test.ts, test/unit/static-middleware.test.ts
Tests cover missing-file resolution, EACCES propagation, synchronous and asynchronous 404 errors, cleared headers, and successful empty assets.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to b2eac

Missing static assets are handled as 404 responses, with no concrete unresolved merge-readiness risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the Conventional Commits format with the fix(static): prefix and accurately describes the missing public asset 404 behavior.
Description check ✅ Passed The description is directly related to the changes. It explains the 404 behavior for unreadable or missing static assets and links the relevant issues.
Linked Issues check ✅ Passed The implementation satisfies both linked issues. Missing assets resolve to a 404, while non-ENOENT read errors still propagate. The changes cover missing source maps and unavailable production public …
Out of Scope Changes check ✅ Passed The implementation and tests are within scope. The added handling for synchronous readers, asynchronous readers, empty assets, and non-ENOENT errors supports the required static asset behavior.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@pkg-pr-new

pkg-pr-new Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4588

commit: b2eac39

pi0 added 2 commits September 7, 2026 12:19
Translate ENOENT inside the generated node reader instead of the runtime
handler, so all three readers share one contract: resolving with no value
means the manifest entry has no data behind it.

This keeps Node errno checks out of `src/runtime`, restores the handler to
a synchronous fallthrough for non-asset requests, and covers the `inline`
reader, which already returned no data for a missing payload and until now
served it as an empty 200.
Both reported cases (nuxt#29078, nuxt#33033) prune the public dir on
purpose - uploading it to a CDN, or stripping sourcemaps after sending
them to Sentry - so the missing file is a standing configuration rather
than a one-off fault, and warning per read only spams the log.
Comment thread src/build/virtual/public-assets.ts Resolved
@danielroe

Copy link
Copy Markdown
Member Author

thank you @pi0 - this is a better approach ❤️

@pi0
pi0 merged commit 23518cd into nitrojs:main Sep 7, 2026
10 of 12 checks passed
@danielroe
danielroe deleted the fix/static-enoent branch October 29, 2026 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants