event-catalog / eventcatalog

An open source documentation tool to bring discoverability to your event-driven architectures
https://eventcatalog.dev
MIT License
1.73k stars 148 forks source link

Watcher raises error in dev mode #851

Open gs-jdudulski opened 1 week ago

gs-jdudulski commented 1 week ago

I tried this:

npx eventcatalog dev or npm run dev on nodes 20.18.0 and 22.5.1

This happened:

Each change raises error:

[1] 15:08:21 watching for file changes...
[0] node:fs:1260
[0]   options = validateRmOptionsSync(path, options, false);
[0]             ^
[0] 
[0] Error: ENOENT: no such file or directory, lstat '/Users/jandudulski/eventcatalog/.eventcatalog-core/src/content/services/ServiceName/4913'
[0]     at Object.rmSync (node:fs:1260:13)
[0]     at file:///Users/jandudulski/eventcatalog/.eventcatalog-core/scripts/watcher.js:65:12 {
[0]   errno: -2,
[0]   code: 'ENOENT',
[0]   syscall: 'lstat',
[0]   path: '/Users/jandudulski/eventcatalog/.eventcatalog-core/src/content/services/ServiceName/4913'
[0] }
[0] 
[0] Node.js v20.18.0
[0] node scripts/watcher.js exited with code 1

I expected this:

Reload server with changes applied

Is there a workaround?

Stop the server and start again

Anything else?

No response

EventCatalog Version

2.8.2

Node.js Version

22.5.1

Platform(s)

MacOS

Community Notes

carlosallexandre commented 1 week ago

Hey @gs-jdudulski,

This error happens to anything you do? Or only when you remove/delete something from your catalog?

gs-jdudulski commented 1 week ago

Anything, on regular edits in files

carlosallexandre commented 1 week ago

Did you try removing the .eventcatalog-core?

gs-jdudulski commented 1 week ago

Just did, still the same.

But googling deeper I figured out it's becuase of... neovim. When editing in anything else it's fine.

Edit: https://github.com/neovim/neovim/issues/3460 oh crap 🤯

gs-jdudulski commented 1 week ago

Every edit emits 3 events for me:

[0] events [
[0]   {
[0]     path: '/Users/jandudulski/eventcatalog/events/ProductDeleted/4913',
[0]     type: 'delete'
[0]   },
[0]   {
[0]     path: '/Users/jandudulski/eventcatalog/events/ProductDeleted/index.md',
[0]     type: 'create'
[0]   },
[0]   {
[0]     path: '/Users/jandudulski/eventcatalog/events/ProductDeleted/index.md~',
[0]     type: 'delete'
[0]   }
[0] ]

I simply add a check to watcher for delete event:

// IF directory remove it
if (type === 'delete' && fs.existsSync(newPath)) {
  fs.rmSync(newPath);
}

And it seems to work but discovered another issue - in neovim I got create event instead of update 🙃

edit: like here https://github.com/parcel-bundler/watcher/issues/98

carlosallexandre commented 1 week ago

@gs-jdudulski

I'm working in a refactor to watcher to handle more edge cases and your scenario is covered there. (PR #764)

This PR handle create and update event in the same way.