5

Here is a gist: https://gist.github.com/973e70bde8e6a530c489

I have two scenarios. One works and one fails even though the code is exactly the same.

  1. Take a CSV file already on the box and parse it. Works perfectly. No issues.
  2. Take a CSV file that was just created and attempt to parse it and I receive:

    ENOENT, no such file or directory '/Users/Home/dev/csv/TwFrI5vhdownload.csv

Same CSV file format and all that. Wouldn't matter anyway because the created file won't even open. It fails with the error above even though the file does exist. If I restart Node and attempt to grab that file, then it works perfectly. If I run fs.stat on the newly created file it fails.

I've tried timeouts, external callbacks, etc.. but with the dynamically created file it always fails.

What am I missing here? Is the file locked and I don't know it?

Thanks!

System:

OSX Lion Node v0.6.7

LU RD
  • 34,438
  • 5
  • 88
  • 296
Brandon
  • 1,399
  • 4
  • 20
  • 37
  • can you access the file via the identical path with any other software? Also what exactly do you mean by "dynamically created file"? – Pointy Jan 29 '12 at 20:49
  • Are you creating the second file, the one that fails, in the same node process? – Fosco Jan 29 '12 at 21:04
  • Yes I can access it. When I say dynamically created, I should say temporary file. It's downloaded from a server and then I try to access it. – Brandon Jan 30 '12 at 00:59
  • @Fosco The file is actually created by Casper using PhantomJS but it's saved in a directory. Then, PhantomJS tells Node the file is there (which it is), but then Node won't open it – Brandon Jan 30 '12 at 01:00
  • I suspect that the Node process simply doesn't have permissions to open that file in that location. – Fosco Jan 30 '12 at 02:11
  • @Fosco That makes sense but why is it when I restart Node the file is accessible? – Brandon Jan 30 '12 at 03:10
  • @Brandon Well, when you restart it, how does Node know the file to open? Does PhantomJS still notify? If not, have you added console logging to ensure that PhantomJS is providing the proper file name/path? – Fosco Jan 30 '12 at 03:22
  • @Fosco I just point to the recently created file and run fs.stat on it and it works fine. If I put the exact same fs.stat function after the file is created while Node is stil running then it throws an error. I know it doesn't make sense. PhantomJS doesn't notify in the traditional sense. It saves the file and then Phantom closes with an echo of the filename after it is created. The file is there and I've tried timeouts to ensure the file has time to register with the file system and it changes nothing. I know it's incredibly frustrating – Brandon Jan 30 '12 at 04:06
  • @Fosco By the way, the actual function that the Node CSV parser is using is fs.createReadStream. I'm not sure how changing that would matter because once again it works after node restarts. – Brandon Jan 30 '12 at 04:09
  • If you are testing with memfs and forgot to add the file *there*, this may occur. Not that I'm speaking from experience or anything ;-) – Brett Zamir Feb 09 '21 at 13:00

1 Answers1

1

Are you sure the file is actually created when you try to parse it?

I took a look on the gist and I guess you are downloading the file from somewhere and then parsing it. Without the whole code I can only guess, but I think that you started the download, but you haven't received a clear indication it is there and ready to be parsed.

Nikolay Tsenkov
  • 1,128
  • 10
  • 26