redwood icon indicating copy to clipboard operation
redwood copied to clipboard

[Bug]: Error: ENOENT: no such file or directory when deleting page directory

Open Tobbe opened this issue 1 year ago • 2 comments

What's not working?

I get the following error when I manually delete a page directory

gen | node:fs:453
gen |     return binding.readFileUtf8(path, stringToFlags(options.flag));
gen |                    ^
gen | 
gen | Error: ENOENT: no such file or directory, open '/Users/tobbe/tmp/rw-test-project-ga-sentry/web/src/pages/DummyPage/DummyPage.tsx'
gen |     at Object.readFileSync (node:fs:453:20)
gen |     at fileToAst (/Users/tobbe/tmp/rw-test-project-ga-sentry/node_modules/@redwoodjs/internal/dist/ast.js:22:28)
gen |     at isPageFile (/Users/tobbe/tmp/rw-test-project-ga-sentry/node_modules/@redwoodjs/internal/dist/files.js:169:34)
gen |     at FSWatcher.<anonymous> (/Users/tobbe/tmp/rw-test-project-ga-sentry/node_modules/@redwoodjs/internal/dist/generate/watch.js:92:99)
gen |     at FSWatcher.emit (node:events:514:28)
gen |     at FSWatcher.emitWithAll (/Users/tobbe/tmp/rw-test-project-ga-sentry/node_modules/chokidar/index.js:541:32)
gen |     at FSWatcher._emit (/Users/tobbe/tmp/rw-test-project-ga-sentry/node_modules/chokidar/index.js:632:8)
gen |     at FSWatcher._remove (/Users/tobbe/tmp/rw-test-project-ga-sentry/node_modules/chokidar/index.js:895:50)
gen |     at FsEventsHandler.handleEvent (/Users/tobbe/tmp/rw-test-project-ga-sentry/node_modules/chokidar/lib/fsevents-handler.js:267:16)
gen |     at FsEventsHandler.checkExists (/Users/tobbe/tmp/rw-test-project-ga-sentry/node_modules/chokidar/lib/fsevents-handler.js:255:12) {
gen |   errno: -2,
gen |   code: 'ENOENT',
gen |   syscall: 'open',
gen |   path: '/Users/tobbe/tmp/rw-test-project-ga-sentry/web/src/pages/DummyPage/DummyPage.tsx'
gen | }
gen | 
gen | Node.js v20.10.0
gen | yarn rw-gen-watch exited with code 1

How do we reproduce the bug?

  1. Create a new empty RW app
  2. yarn rw dev in terminal 1
  3. yarn rw g page Dummy in terminal 2
  4. rm -fr web/src/pages/DummyPage also in terminal 2

You'll now see the error in terminal 1

What's your environment? (If it applies)

❯ yarn rw info        

  System:
    OS: macOS 14.1.1
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - /private/var/folders/7j/9p56mwmj6jsfdr2h5_884j9w0000gn/T/xfs-e0cad5fb/node
    Yarn: 4.0.2 - /private/var/folders/7j/9p56mwmj6jsfdr2h5_884j9w0000gn/T/xfs-e0cad5fb/yarn
  Databases:
    SQLite: 3.39.5 - /usr/bin/sqlite3
  Browsers:
    Safari: 17.1
  npmPackages:
    @redwoodjs/core: 7.0.0-canary.840 => 7.0.0-canary.840+d7d703d88

Are you interested in working on this?

  • [X] I'm interested in working on this

Tobbe avatar Jan 16 '24 13:01 Tobbe

The problem is that we have a file watcher running that detects when files are deleted to update our generated types. It runs functions like isPageFile, isCell etc. They in turn use fileToAst to get information about the code in the files, like what exports they have etc. This works great for new files that are created. But for files that are deleted we can't do that because we can't read the contents of deleted files...

Either we're less exact in our isX functions for files that are deleted. Or we'll have to come up with another method.

One idea I just had while typing this all out would be to keep a cache(-file?) of all files detected on startup and on file creation, and then just match against that cache when a file is deleted to know what kind of file it was.

Tobbe avatar Jan 16 '24 13:01 Tobbe

A simpler idea if I understood the problem couldn't be just force to restart the server?

TheoOliveira avatar Aug 17 '24 18:08 TheoOliveira