Skip to content

Improve error message when the assets directory path points to a file instead of a directory#13115

Merged
petebacondarwin merged 1 commit intomainfrom
dario/better-error-message-ENOTDIR-assets-dir
Mar 30, 2026
Merged

Improve error message when the assets directory path points to a file instead of a directory#13115
petebacondarwin merged 1 commit intomainfrom
dario/better-error-message-ENOTDIR-assets-dir

Conversation

@dario-piotrowicz
Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz commented Mar 29, 2026

If users mistakenly specify a path pointing to a file for assets they receive an unpolished/slightly confusing error message like so:

ENOTDIR: not a directory, open '<path>/_redirects'

This PR simply improves this error message so that we clearly tell the user what the issue is:

The directory specified by the "assets.directory" field in your configuration file is not a directory:
  <path>

Example:

Before After
Screenshot of error message before Screenshot of error message after

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: self-documenting UX improvement

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@dario-piotrowicz dario-piotrowicz requested a review from a team as a code owner March 29, 2026 21:06
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 29, 2026

🦋 Changeset detected

Latest commit: 5d38f9e

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Mar 29, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@github-actions
Copy link
Copy Markdown
Contributor

✅ All changesets look good

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 29, 2026

I've now reviewed the entire PR. Let me check the error message wording closely:

  • NonExistentAssetsDirError: "The directory specified by the ..." — uses "--assets" command line argument
  • NonDirectoryAssetsDirError: "The path specified by the ..." — uses "--assets" command line argument

But looking at the test expectations more carefully:

  • The deploy test for --assets expects: The path specified by the "--assets" command line argument doesn't point to a directory
  • The dev test for --assets expects: The path specified by the "--assets" command line argument doesn't point to a directory

The wording is consistent between tests and source. The existing error says "directory specified by" while the new one says "path specified by" — this is appropriate since in the new case it's not a directory.

Let me now verify the behavior at the getPlatformProxy call site. The new NonDirectoryAssetsDirError would correctly NOT be caught by the instanceof NonExistentAssetsDirError check, which is the right behavior — a file existing at that path is a user error that should surface.

The overall change is clean:

  1. Replaces existsSync with statSync (single syscall instead of two)
  2. Adds early detection for non-directory paths
  3. Proper error class hierarchy
  4. Good test coverage for both dev and deploy commands, both CLI flag and config file sources
  5. Formatter line-break changes are cosmetic (likely from oxfmt)
  6. Changeset is correct

LGTM

github run

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 29, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13115

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13115

miniflare

npm i https://pkg.pr.new/miniflare@13115

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13115

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13115

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13115

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13115

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13115

wrangler

npm i https://pkg.pr.new/wrangler@13115

commit: 5d38f9e

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Mar 30, 2026
@petebacondarwin petebacondarwin merged commit 2565b1d into main Mar 30, 2026
51 of 54 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Mar 30, 2026
@petebacondarwin petebacondarwin deleted the dario/better-error-message-ENOTDIR-assets-dir branch March 30, 2026 13:21
NuroDev pushed a commit that referenced this pull request Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants