eventcatalog icon indicating copy to clipboard operation
eventcatalog copied to clipboard

DS_Store files created by finder on mac result in Server Errors

Open hdeweirdt opened this issue 2 years ago • 9 comments

Have you read the Contributing Guidelines on issues?

Description

After opening a folder on MacOS using their Finder program, it creates .DS_Store files automatically. When starting the server and browsing to a directory (events, services or event the homepage) a "Server Error" is shown:

Steps to reproduce

  1. Open one of the program directories, can be the root or events, services,... using Finder
  2. Start the server (npm run dev)
  3. A crash occurs when viewing the page associated with a folder containing a .DS_Store file.

Expected behavior

No crash should occur even if there is a .DS_Store file, these files should be ignored.

Actual behavior

Server Error

Error: ENOTDIR: not a directory, open '/Users/harm/Projects/cashless-pay/docs/event-catalog/events/.DS_Store/index.md'
This error happened while generating the page. Any console logs will be displayed in the terminal window.
Source
Object.openSync
node:fs (585:3)
Object.readFileSync
node:fs (453:35)

lib/file-reader.ts (19:15) @ readMarkdownFile

  17 | 
  18 | export const readMarkdownFile = (pathToFile: string) => {
> 19 |   const file = fs.readFileSync(pathToFile, {
     |               ^
  20 |     encoding: 'utf-8',
  21 |   });
  22 |   return matter(file);

Call Stack
eval
lib/events.ts (136:38)
Array.map
<anonymous>
getAllEvents
lib/events.ts (135:17)
getStaticProps
pages/events.tsx (252:29)
Object.renderToHTML
file:/Users/harm/Projects/cashless-pay/docs/event-catalog/node_modules/next/dist/server/render.js (442:26)
async doRender
file:/Users/harm/Projects/cashless-pay/docs/event-catalog/node_modules/next/dist/server/base-server.js (855:38)
async
file:/Users/harm/Projects/cashless-pay/docs/event-catalog/node_modules/next/dist/server/base-server.js (950:28)

Your environment

  • EventCatalog version used: 0.0.1
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): node 8.3.1, firefox 97
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): MacOS 12.2.1

hdeweirdt avatar Feb 16 '22 12:02 hdeweirdt

I have the same behavior when I want to add empty events or services folder by adding .gitkeep or .gitignore

akhansari avatar Mar 02 '22 15:03 akhansari

Hi @hdeweirdt

Thanks for raising the issue.

I wasn't aware that the DS_Store looks like a folder here?

'/Users/harm/Projects/cashless-pay/docs/event-catalog/events/.DS_Store/index.md'

Is that correct on your file system?

boyney123 avatar Mar 04 '22 07:03 boyney123

➜  events git:(main) ls -al .DS_Store 
-rw-r--r--@ 1 harm  staff  6148 Mar  7 09:23 .DS_Store
➜  events git:(main) cd .DS_Store
cd: not a directory: .DS_Store

The @ means it's a symbolic link, but it won't resolve to a location. I'm new to MacOS so don't fully get that .DS_Store either.

hdeweirdt avatar Mar 07 '22 08:03 hdeweirdt

Same error in my laptop. Seems that .DS_Store files are being considered as folders.

Terminal output:

error - Error: ENOTDIR: not a directory, open '/Users/carlos/Documents/Pro/Project/CommonDocumentation/IT/domain-service-catalog/domains/.DS_Store/index.md'

<w> [webpack.cache.PackFileCacheStrategy] Skipped not serializable cache item 'Compilation/modules|/Users/carlos/Documents/Pro/Project/CommonDocumentation/IT/domain-service-catalog/node_modules/next/dist/build/webpack/loaders/css-loader/src/index.js??ruleSet[1].rules[3].oneOf[8].use[1]!/Users/carlos/Documents/Pro/Project/CommonDocumentation/IT/domain-service-catalog/node_modules/next/dist/build/webpack/loaders/postcss-loader/src/index.js??ruleSet[1].rules[3].oneOf[8].use[2]!/Users/carlos/Documents/Pro/Project/CommonDocumentation/IT/domain-service-catalog/.eventcatalog-core/styles/globals.css': No serializer registered for Warning
<w> while serializing webpack/lib/cache/PackFileCacheStrategy.PackContentItems -> webpack/lib/NormalModule -> Array { 3 items } -> webpack/lib/ModuleWarning -> Warning

Your environment

EventCatalog version used: 0.0.1
Environment name and version Firefox 100.0.2, Node.js 15.14.0
Operating system and version: MacOS 12.4 MacBook Pro M1 2020

medaqueno avatar May 26 '22 16:05 medaqueno

Not a solution but a quick fix to not get stuck is to add a basic command for removing those files before building:

"build": "npm run clean && eventcatalog build",
"clean": "find . -name '.DS_Store' -type f -delete",

There is no real danger in removing them, so this should be safe and good.

On another note I did a 10-second test by just adding an fs.existsSync(dir) to return empty if the relevant code path is not a directory but the logic is deeper than that, so we still need to spend a bit more effort getting that to work beyond that basic check.

mikaelvesavuori avatar Jun 30 '22 07:06 mikaelvesavuori

Thanks for giving a solution @mikaelvesavuori

For anyone having this issue maybe it's worth having that clean script @mikaelvesavuori has added.

I'm happy to add the clean script to all catalogs (using create-catalog) but I'm not sure if that would work for windows users, any ideas @mikaelvesavuori ?

boyney123 avatar Jul 07 '22 16:07 boyney123

Since the command will be unrecognized on Windows, and also since the .DS_Store will never be generated on a Windows machine, it is all completely Linux/Mac oriented. I advise against putting this in EventCatalog, though the checks in the code should ignore/not return non-directory items—i.e. solving the actual problem, rather than its symptom.

mikaelvesavuori avatar Jul 07 '22 17:07 mikaelvesavuori

Thanks for the workaround @mikaelvesavuori! The clean script works perfectly.

jmisner-zp avatar Aug 19 '22 16:08 jmisner-zp

Thanks for the workaround @mikaelvesavuori !

yeseniamolinab avatar Oct 11 '22 20:10 yeseniamolinab