purescript-node / purescript-node-fs

Node.js file I/O for purescript
MIT License
33 stars 34 forks source link

`stat` can result in unexpected runtime failures #27

Closed Thimoteus closed 8 years ago

Thimoteus commented 8 years ago

This is a failing example that's close to what I was using.

I'm not sure if the problem is with stat or catchException, but essentially this is the problem:

You can use catchException to discharge an EXCEPTION assumption from your program. Great! If we use enough catchExceptions, the compiler tells us (assuming everything was well-typed) that our program won't have any uncaught exceptions at runtime.

Except it does. catchException doesn't ... catch the exception ... when using stat on a path that doesn't exist.

This threw me for a loop since I was assuming that uncaught runtime exceptions wouldn't happen.

hdgarrood commented 8 years ago

:scream: this definitely shouldn't happen.

Perhaps we incorrectly assumed the error would be thrown immediately if fs.statSync failed? I'm not at my laptop right now but does it work in node using JS directly if you try to wrap fs.statSync in a try...catch block?

Thimoteus commented 8 years ago

It seems to work as intended in node:

> try {
... fs.statSync('./something');
... } catch (e) {
... console.log(e);
... }
{ [Error: ENOENT: no such file or directory, stat './something']
  errno: -2,
  code: 'ENOENT',
  syscall: 'stat',
  path: './something' }
hdgarrood commented 8 years ago

Fixed by https://github.com/purescript-node/purescript-node-fs/commit/b1a99f855a245e1031a91e33ff218b5531c0033e, released in 0.9.3. Thanks for the report! :)

hdgarrood commented 8 years ago

Oops, I meant v0.10.1. I really need to get on and implement pulp version to protect me from myself.