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}