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: ${
      } old:${JSON.stringify(folder_info)} new:${JSON.stringify(
      Sentry.captureException(new Error(debug));

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


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


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!



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);

    } catch(error) {

Tracking this here:

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