Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Error: ENOENT: no such file or directory, unlink './modules/users/client/img/profile/uploads/df9f321cf61c57c89c3e4d0a416e1093.jpg' #1778

Closed
maelfosso opened this issue May 21, 2017 · 3 comments

Comments

@maelfosso
Copy link

Hi,

Please I always have this error
I don't know why

How could I solve it please ?

Thanks.

@vaucouleur
Copy link
Contributor

vaucouleur commented May 22, 2017

@maelfosso When you change your profile picture, the current version of meanjs tries to delete the existing profile picture (pictures are not stored within mongodb, they are stored on the filesystem).

fs.unlink(existingImageUrl, function (unlinkError) {

My guess is that, you played with meansjs, you modified some profile picture, then you re-deployed meanjs somewere else on your filesystem (or you deleted altogether the previous install).. but you kept the existing mongodb database.. hence the exception when you are trying to change your profile picture.

If this scenario is indeed what happened, you can fix it by either:

  • simply adding a default image df9f321cf61c57c89c3e4d0a416e1093.jpg
  • modify directly your mongodb database, to fix the reference to the missing picture
  • modify the code of deleteOldImage so that it does not reject the promise on unlink error..

@sagarora77
Copy link

Totally agree with @vaucouleur.
Its not an issue, its just a broken link which is left in MongoDB after you removed the project or reinstalled in a different directory as the resource is not present in the uploads directory.

@mleanos
Copy link
Member

mleanos commented Jul 24, 2017

modify the code of deleteOldImage so that it does not reject the promise on unlink error..

Exactly what @vaucouleur said.

In the case of a missing file, or bad reference in the User's profileImageUrl field, we probably shouldn't throw an error and send it back to the user.

We should just log the error to the console in the case of when the file isn't found.

https://github.com/meanjs/mean/blob/master/modules/users/server/controllers/users/users.profile.server.controller.js#L112

We can change the callback logic to something like:

if (unlinkError) {
  console.log(unlinkError);
  if (unlinkError.code === 'ENOENT') {
    // NO NEED TO RETURN ERROR IN THIS CASE
    return resolve();
  }

  reject({
    message: 'Error occurred while deleting old profile picture'
  });
} else {
  resolve();
}

I'm also skeptical of whether or not we should return any errors from the unlink. It doesn't seem relevant to the User's experience to know if the file was removed. We might just want to silently log any errors here, and then handle it server-side if necessary.

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

No branches or pull requests

4 participants