Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview Crash Due to Temporary Files Created by Vim #1498

Closed
jesusgollonet opened this issue Jul 2, 2024 · 2 comments · Fixed by #1700
Closed

Preview Crash Due to Temporary Files Created by Vim #1498

jesusgollonet opened this issue Jul 2, 2024 · 2 comments · Fixed by #1700
Assignees
Labels
bug Something isn’t working

Comments

@jesusgollonet
Copy link

Description:

When running npm run dev in one of the Observable examples, the engine frequently crashes. Upon investigation, I discovered that this issue is caused by Vim creating temporary files with a tilde (~) at the end, and then removing them. This triggers the engine to crash.

Steps to Reproduce

1.	Clone the repository and navigate to the example directory.
2.	Run npm install to install dependencies.
3.	Run npm run dev to start the preview.
4.	Edit any file in the project using Vim.
5.	Observe the engine crash when Vim creates and removes temporary files.

Expected Behavior:

The engine should handle the creation and removal of temporary files without crashing.

Actual Behavior:

The engine crashes whenever Vim creates and then removes temporary files with a tilde (~) at the end.

Environment:

•	OS: OsX Sonoma 14
•	Node.js version: 18
•	Observable framework version: 1.9.0

Additional Information:

It would be helpful to implement a mechanism to ignore temporary files created by text editors like Vim to prevent the engine from crashing during development.

Error Log

(note the ~ at the end of the file):

files: { removed: [], added: [] },
  tables: { removed: [], added: [] },
  stylesheets: { removed: [], added: [] },
  hash: {
    previous: '3cb45ab6f46b2e57f7e8da80f4cb9335fa5d7add83800cfc8555870c52ecb924',
    current: 'c098d0643d4f0858f7a1929094b1330fcf5fb8b442495d553437debec11586f7'
  }
}
node:fs:1690
  handleErrorFromBinding(ctx);
  ^

Error: ENOENT: no such file or directory, stat 'src/test.md~'
    at statSync (node:fs:1690:3)
    at visitFiles (file:///Users/jgb/Sketch/2024-07-01_19.39.22_observable-tutorial/hello-framework/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@observablehq/framework/dist/files.js:37:20)
    at visitFiles.next (<anonymous>)
    at visitMarkdownFiles (file:///Users/jgb/Sketch/2024-07-01_19.39.22_observable-tutorial/hello-framework/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@observablehq/framework/dist/files.js:27:14)
    at visitMarkdownFiles.next (<anonymous>)
    at readPages (file:///Users/jgb/Sketch/2024-07-01_19.39.22_observable-tutorial/hello-framework/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@observablehq/framework/dist/config.js:42:14)
    at Object.get [as pages] (file:///Users/jgb/Sketch/2024-07-01_19.39.22_observable-tutorial/hello-framework/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@observablehq/framework/dist/config.js:122:57)
    at watcher (file:///Users/jgb/Sketch/2024-07-01_19.39.22_observable-tutorial/hello-framework/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@observablehq/framework/dist/preview.js:280:55) {
  errno: -2,
  syscall: 'stat',
  code: 'ENOENT',
  path: 'src/test.md~'
}
@jesusgollonet jesusgollonet added the bug Something isn’t working label Jul 2, 2024
@jesusgollonet
Copy link
Author

I of course can make vim not generate those files, but I have never had to do that before.

Raising because I got this issue yesterday while trying framework for the first time and the constant crashes made me almost give up on it. And I would have missed out!

A naive attempt that seems to fix this is to just ignore files that end with tilde in visitFiles, as they are quite likely backup files from vim. I quickly tried on the generated js code and crashes stopped. Haven't checked if this affects anything else.

function* visitFiles(root) {
  const visited = /* @__PURE__ */ new Set();
  const queue = [root = normalize(root)];
  for (const path of queue) {
     if (path.lastIndexOf('~') > -1){
        continue;
    }
    const status = statSync(path);
    if (status.isDirectory()) {
      if (visited.has(status.ino))
        continue;
...

@ruuda
Copy link

ruuda commented Sep 30, 2024

IntelliJ also creates such temporary files on save.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants