From b8e6fc5cb0ad206264e00240c1e689b31d4a8c2e Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 10 Jan 2017 22:10:00 -0800 Subject: [PATCH] Do not fatal when formatting throws When you are formatting an entire codebase and a single file throw, it shouldn't stop the entire process. --- bin/prettier.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/bin/prettier.js b/bin/prettier.js index 6e00d0b2..d2c2e935 100755 --- a/bin/prettier.js +++ b/bin/prettier.js @@ -39,14 +39,21 @@ filenames.forEach(filename => { return; } - const output = jscodefmt.format(input, { - printWidth: argv["print-width"], - tabWidth: argv["tab-width"], - bracketSpacing: argv["bracket-spacing"], - useFlowParser: argv["flow-parser"], - singleQuote: argv["single-quote"], - trailingComma: argv["trailing-comma"] - }); + let output; + try { + output = jscodefmt.format(input, { + printWidth: argv["print-width"], + tabWidth: argv["tab-width"], + bracketSpacing: argv["bracket-spacing"], + useFlowParser: argv["flow-parser"], + singleQuote: argv["single-quote"], + trailingComma: argv["trailing-comma"] + }); + } catch (e) { + process.exitCode = 2; + console.error(e); + return; + } if (write) { fs.writeFile(filename, output, "utf8", err => {