Skip to content

Commit 2c6a33b

Browse files
authored
fix: Fixes uncaught errors in concurrency loop (#95)
# Description Concurrency was added for parallel uploads which introduced a bug where the try/catch wrapping this didn't properly catch the errors being thrown from within the async functions. This moves the try/catch inside of each upload process ## Issue Ticket Number <!-- Specifiy which issue this fixes by referencing the issue number (`#11`) or issue URL. --> <!-- Example: Fixes #1 --> Fixes #94 ## Type of change <!-- Please select all options that are applicable. --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update # Checklist <!-- These must all be followed and checked. --> - [ ] I have followed the contributing guidelines of this project as mentioned in [CONTRIBUTING.md](/CONTRIBUTING.md) - [ ] I have created an [issue](https://github.com/colbyfayock/netlify-plugin-cloudinary/issues) ticket for this PR - [ ] I have checked to ensure there aren't other open [Pull Requests](https://github.com/colbyfayock/netlify-plugin-cloudinary/pulls) for the same update/change? - [ ] I have performed a self-review of my own code - [ ] I have run tests locally to ensure they all pass - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes needed to the documentation
1 parent df8c8c9 commit 2c6a33b

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

netlify-plugin-cloudinary/src/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ export async function onBuild({
204204
);
205205
}
206206

207-
try {
208-
const limitUploadFiles = pLimit(uploadConcurrency);
209-
const uploadsQueue = imagesFiles.map(image => {
210-
const publishPath = image.replace(PUBLISH_DIR, '');
211-
return limitUploadFiles(() => {
212-
async function uploadFile() {
207+
const limitUploadFiles = pLimit(uploadConcurrency);
208+
const uploadsQueue = imagesFiles.map((image, i) => {
209+
const publishPath = image.replace(PUBLISH_DIR, '');
210+
return limitUploadFiles(() => {
211+
async function uploadFile() {
212+
try {
213213
const cloudinary = await getCloudinaryUrl({
214214
deliveryType,
215215
folder,
@@ -224,15 +224,15 @@ export async function onBuild({
224224
publishPath,
225225
...cloudinary,
226226
};
227+
} catch(e) {
228+
globalErrors.push(e);
227229
}
228-
return uploadFile();
229-
})
230+
}
231+
return uploadFile();
230232
})
233+
})
231234

232-
_cloudinaryAssets.images = await Promise.all(uploadsQueue);
233-
} catch (e) {
234-
globalErrors.push(e)
235-
}
235+
_cloudinaryAssets.images = await Promise.all(uploadsQueue);
236236

237237
// If the delivery type is set to upload, we need to be able to map individual assets based on their public ID,
238238
// which would require a dynamic middle solution, but that adds more hops than we want, so add a new redirect

0 commit comments

Comments
 (0)