From 38483a40294aaf5bf779d607c71dec463264a312 Mon Sep 17 00:00:00 2001 From: knidarkness Date: Mon, 30 Sep 2019 12:50:38 +0300 Subject: [PATCH] added try/catch for JSON parsing and fail fast approach if JSON is invalid --- cli/index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cli/index.ts b/cli/index.ts index 5c02a6f3..7bb27bb2 100644 --- a/cli/index.ts +++ b/cli/index.ts @@ -357,8 +357,13 @@ function handleError(error: Error) { } function getObjectOrJSON(options) { - return options && typeof options === 'string' - ? JSON.parse(options) : options - ? options - : {}; + try { + return options && typeof options === 'string' + ? JSON.parse(options) : options + ? options + : {}; + } catch (e) { + console.log(`Encountered error:\n${options}\nis not a valid JSON.`); + handleError(e); + } }