From 62fb0577cbde77d1fc9b47498421aeb7050530b7 Mon Sep 17 00:00:00 2001 From: Ben Scott Date: Fri, 29 Nov 2024 14:25:47 -0800 Subject: [PATCH] Improve debug message when json parsing fails in e2e tests --- test/stylelint-prettier-e2e.test.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/stylelint-prettier-e2e.test.js b/test/stylelint-prettier-e2e.test.js index 2ccbc15..23431d8 100644 --- a/test/stylelint-prettier-e2e.test.js +++ b/test/stylelint-prettier-e2e.test.js @@ -113,8 +113,17 @@ function runStylelint(pattern) { const result = spawnSync(stylelintCmd, ['--formatter=json', pattern], { cwd: stylelintCwd, }); - - const jsonErrors = JSON.parse(result.stderr.toString().trim()); + const resultContent = result.stderr.toString().trim(); + + let jsonErrors; + try { + jsonErrors = JSON.parse(resultContent); + } catch (err) { + throw new Error( + `Could not parse json from stderr. Attempted to parse:\n${resultContent}`, + {cause: err} + ); + } const errorLines = [];