From e28cdc8a4a126ea646014ce406c0874f40afaf79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Tue, 22 Feb 2022 11:37:21 +0100 Subject: [PATCH] throw error when public folder could not be created --- packages/core/strapi/lib/core/bootstrap.js | 10 ++++++++-- packages/providers/upload-local/lib/index.js | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/core/strapi/lib/core/bootstrap.js b/packages/core/strapi/lib/core/bootstrap.js index 8b31596307..8fc465d574 100644 --- a/packages/core/strapi/lib/core/bootstrap.js +++ b/packages/core/strapi/lib/core/bootstrap.js @@ -3,7 +3,7 @@ const { getConfigUrls } = require('@strapi/utils'); const fse = require('fs-extra'); -module.exports = function({ strapi }) { +module.exports = async function({ strapi }) { strapi.config.port = strapi.config.get('server.port') || strapi.config.port; strapi.config.host = strapi.config.get('server.host') || strapi.config.host; @@ -25,5 +25,11 @@ module.exports = function({ strapi }) { } // ensure public repository exists - fse.ensureDir(strapi.dirs.public); + try { + await fse.ensureDir(strapi.dirs.public); + } catch (e) { + throw new Error( + `The public folder (${strapi.dirs.public}) doesn't exist. Please make sure it exists.` + ); + } }; diff --git a/packages/providers/upload-local/lib/index.js b/packages/providers/upload-local/lib/index.js index 90b24ee079..4f8b7fea32 100644 --- a/packages/providers/upload-local/lib/index.js +++ b/packages/providers/upload-local/lib/index.js @@ -22,7 +22,13 @@ module.exports = { // Ensure uploads folder exists const uploadPath = path.resolve(strapi.dirs.public, UPLOADS_FOLDER_NAME); - fse.ensureDirSync(uploadPath); + try { + fse.ensureDirSync(uploadPath); + } catch (e) { + throw new Error( + `The upload folder (${uploadPath}) doesn't exist. Please make sure it exists.` + ); + } return { upload(file) {