Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 5621fde

Browse files
committed
fix crash when renaming file (or deleting it) after adding it
1 parent e6e2ed2 commit 5621fde

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

app/actions/bundleManageResources.actions.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -767,17 +767,23 @@ function getFileSizes(newlyAddedFilePaths) {
767767
return async (dispatch, getState) => {
768768
const { fileSizes: fileSizesOrig = {} } = getState().bundleManageResources;
769769
const fileSizesPromises = newlyAddedFilePaths.map(async filePath => {
770-
const stats = await fs.stat(filePath);
771-
const { size: sizeRaw } = stats;
772-
const size = utilities.formatBytesByKbs(sizeRaw);
773-
return { filePath, size };
770+
try {
771+
const stats = await fs.stat(filePath);
772+
const { size: sizeRaw } = stats;
773+
const size = utilities.formatBytesByKbs(sizeRaw);
774+
return { filePath, size };
775+
} catch (error) {
776+
console.error(error); // returns undefined data
777+
}
774778
// const checksum = size < 268435456 ? await md5File(filePath) : '(too expensive)';
775779
});
776780
const fileSizesList = await Promise.all(fileSizesPromises);
777-
const fileSizes = fileSizesList.reduce((acc, data) => {
778-
acc[data.filePath] = data.size;
779-
return acc;
780-
}, fileSizesOrig);
781+
const fileSizes = fileSizesList
782+
.filter(data => data !== undefined)
783+
.reduce((acc, data) => {
784+
acc[data.filePath] = data.size;
785+
return acc;
786+
}, fileSizesOrig);
781787
dispatch({
782788
type: bundleResourceManagerConstants.UPDATE_FILE_STATS_SIZES,
783789
fileSizes

0 commit comments

Comments
 (0)