makeDirectoryAsync() error "could not be created"

I’m getting Sentry reports from some of my Android customers who get errors during makeDirectoryAsync(). The error is “Directory xxx could not be created”.

The odd thing is that if I call getInfoAsync() after it fails, the directory has actually been created. It looks like await makeDirectoryAsync() reported failure early but then went on to create it anyway.

To debug it I made a function that creates a directory that doesn’t exist. On error it shows the directory existence before and after:

// Create any app folders that don't already exist
export const checkAndCreateFolder = async folder_path => {
  const folder_info = await Expo.FileSystem.getInfoAsync(folder_path);
  if (!Boolean(folder_info.exists)) {
    // Create folder
    try {
      await FileSystem.makeDirectoryAsync(folder_path, {
        intermediates: true
      });
    } catch (error) {
      // Report folder creation error, include the folder existence before and now
      const new_folder_info = await Expo.FileSystem.getInfoAsync(folder_path);
      const debug = `checkAndCreateFolder: ${
        error.message
      } old:${JSON.stringify(folder_info)} new:${JSON.stringify(
        new_folder_info
      )}`;
      console.log(debug);
      Sentry.captureException(new Error(debug));
    }
  }
};

The Sentry reports show that before creation getInfoAsync() returned:

{"isDirectory":false,"exists":false}

And after makeDirectoryAsync() failed and returned “could not be created” getInfoAsync() shows it actually exists:

{"size":4096,"modificationTime":1532552616,"uri":"file:///data/data/com.test.test/files/ExperienceData/%2540test%252Ftest/subfolder","isDirectory":true,"exists":true}

Hey @mlight,

Thanks for the detailed report. I pinged internally about this. Either I or one of the team members will hop in when we know more!

Cheers,

Adam

1 Like

I’m also receiving this error with makeDirectoryAsync(). To replicate is simple:

try {
      let folder = FileSystem.documentDirectory + "testfolder"
      await FileSystem.makeDirectoryAsync(folder, {
        intermediates: true
      })

      var fi = await FileSystem.getInfoAsync(folder);

      alert(JSON.stringify(fi))
    } catch(error) {
      alert(error)
    }
2 Likes

Tracking this here: https://github.com/expo/expo/issues/2050

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.