Closed bodri5 closed 8 years ago
Assuming we still want to attempt to create the directory if it doesn't exist, then the patch needs some work. I'll add comments inline.
I fixed the indentations.
I do not quite understand @jhpedemonte's other comment. My code works the following way: first stat the path with fs.statSync. If it does not exist, then fs.statSync throws an exception, and only then we try to create the directory with fs.mkdirSync. As we are already sure, that it does not exists, any exception from mkdir can abort the program unconditionally.
@bodri5: My suggested code change was meant to address two things:
fs.statSync
can throw many exceptions. The only one we want to handle is ENOENT
(does not exist). All other exceptions should abort the program (hence the additional throw e
in the else
case).any exception from mkdir can abort the program unconditionally
-> This is true and also handled in my code sample above. I just wanted to explicitly write out an error string that is more understandable to the user (the console.error
line).Make sense?
@jhpedemonte: Thank you for the explanation. Modified the patch according to your suggestions.
Travis was having issues, but now this is passing. I tested locally as well, pointing NOTEBOOKS_DIR
at legitimate directories, a file and dir to which I didn't have permissions. All worked as expected. Merging.
Thanks @bodri5
Revised version of #268