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

Error returned when file name exists #2

Closed
Nateowami opened this issue Sep 15, 2016 · 2 comments
Closed

Error returned when file name exists #2

Nateowami opened this issue Sep 15, 2016 · 2 comments

Comments

@Nateowami
Copy link

I'm having an issue that an error is returned to the callback if a file with the given name already exists.

My format string is is %f%i. What I'm trying to do is preserve the original file name as much as possible, but when a second file.txt is uploaded, name it something like file2.txt. This seems like a pretty standard use-case.

What happens is, main.js:52 calls fs.exists. Upon finding that the file exists, main.js:60 calls back with the "error", which is actually just true. Error handlers then log true and nothing more (that took awhile to debug!).

I think there are two issues here:

  • An error should be constructed, so there will be a message and a stack trace.
  • If I'm understanding correctly, it seems it should increment the counter (%i) and try again. Am I wrong?

Looking a bit deeper I think I see the issue. fs.exists calls back with a single argument (very unconventional for Node.js, and apparently the main reason for its deprecation.), telling whether the file exists. The onExists function (main.js:58) expects the first argument to be err. Hence, when the file exists, it calls back with true rather than trying another iteration.

This might be a good time to switch to fs.open, probably using the wx+ mode (fs.exists being deprecated). In that case it would be necessary to catch errors from fs.open that will be thrown if the file exits already.

I can't commit to anything, but I might be able to submit a pull request.

@koopero
Copy link
Owner

koopero commented Sep 17, 2016

I have published a new version ( 0.1.5 ), which fixes this problem.
Thanks for the bug report.

@koopero koopero closed this as completed Sep 17, 2016
@Nateowami
Copy link
Author

Thanks! I'll give it a try. And thanks for updating the documentation clarifying the difference between %f and %b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants