From 15248bf85ac414b84653cb7bd522feb8eed80fe9 Mon Sep 17 00:00:00 2001 From: Peter Fernandes Date: Wed, 9 Dec 2020 17:14:43 -0500 Subject: [PATCH 1/2] Validate that input files exist before attempting to process them --- cli/src/index.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cli/src/index.js b/cli/src/index.js index 933ab975..ebcca099 100644 --- a/cli/src/index.js +++ b/cli/src/index.js @@ -4,6 +4,7 @@ import { isMainThread } from 'worker_threads'; import { cpus } from 'os'; import { extname, join, basename } from 'path'; import { promises as fsp } from 'fs'; +import { resolve as resolvePath } from 'path'; import { version } from 'json:../package.json'; import ora from 'ora'; import kleur from 'kleur'; @@ -182,7 +183,30 @@ function progressTracker(results) { return tracker; } +async function checkInputFilesValid(files) { + const validFiles = []; + + for (const file of files) { + try { + await fsp.stat(file); + } catch (err) { + if (err.code === 'ENOENT') { + console.warn( + `Warning: Input file does not exist: ${resolvePath(file)}`, + ); + continue; + } else throw err; + } + + validFiles.push(file); + } + + return validFiles; +} + async function processFiles(files) { + files = await checkInputFilesValid(files); + const parallelism = cpus().length; const results = new Map(); From b5f708a1e65cf06e5f5f899f15e212d0fc404dfc Mon Sep 17 00:00:00 2001 From: Peter Fernandes Date: Wed, 9 Dec 2020 17:17:31 -0500 Subject: [PATCH 2/2] Fix formatting --- cli/src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/src/index.js b/cli/src/index.js index ebcca099..d7c97eda 100644 --- a/cli/src/index.js +++ b/cli/src/index.js @@ -195,7 +195,9 @@ async function checkInputFilesValid(files) { `Warning: Input file does not exist: ${resolvePath(file)}`, ); continue; - } else throw err; + } else { + throw err; + } } validFiles.push(file);