From ca44af06258298a3f8fb5142838d577366c22358 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Mon, 25 Jan 2021 10:56:23 +0000 Subject: [PATCH] Prevent crash when coreNodesDir is empty (#2831) * Fix for HTTP-Request not sending body for GET Background in SO question: https://stackoverflow.com/q/60356824/504554 * Prevent crash when coreNodesDir points to empty dir This should prevent a crash when you point to an empty core nodes directory. * Matching upstream master --- .../@node-red/registry/lib/library.js | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/node_modules/@node-red/registry/lib/library.js b/packages/node_modules/@node-red/registry/lib/library.js index a8ca8a775..c45282b89 100644 --- a/packages/node_modules/@node-red/registry/lib/library.js +++ b/packages/node_modules/@node-red/registry/lib/library.js @@ -28,17 +28,19 @@ function getFlowsFromPath(path) { fs.readdir(path,function(err,files) { var promises = []; var validFiles = []; - files.forEach(function(file) { - var fullPath = fspath.join(path,file); - var stats = fs.lstatSync(fullPath); - if (stats.isDirectory()) { - validFiles.push(file); - promises.push(getFlowsFromPath(fullPath)); - } else if (/\.json$/.test(file)){ - validFiles.push(file); - promises.push(Promise.resolve(file.split(".")[0])) - } - }) + if (files) { + files.forEach(function(file) { + var fullPath = fspath.join(path,file); + var stats = fs.lstatSync(fullPath); + if (stats.isDirectory()) { + validFiles.push(file); + promises.push(getFlowsFromPath(fullPath)); + } else if (/\.json$/.test(file)){ + validFiles.push(file); + promises.push(Promise.resolve(file.split(".")[0])) + } + }) + } var i=0; Promise.all(promises).then(function(results) { results.forEach(function(r) {