From 05d53084c14ac79517a424a313429ef780d58325 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Tue, 1 Nov 2016 05:47:18 -0700 Subject: [PATCH] buck worker tool: catch errors thrown from commands, and respond with errors. Reviewed By: cpojer Differential Revision: D4057884 fbshipit-source-id: acfe0cc57b541a534dd640380c69f591c1fb83c6 --- react-packager/src/ModuleGraph/worker.js | 50 +++++------------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/react-packager/src/ModuleGraph/worker.js b/react-packager/src/ModuleGraph/worker.js index c604d5fb..2a15f3b1 100644 --- a/react-packager/src/ModuleGraph/worker.js +++ b/react-packager/src/ModuleGraph/worker.js @@ -29,14 +29,8 @@ const defaultVariants = {default: {}}; const moduleFactoryParameters = ['require', 'module', 'global', 'exports']; function transformJSON(infile, options, outfile, callback) { - let json, value; - try { - json = fs.readFileSync(infile, 'utf8'); - value = JSON.parse(json); - } catch (readError) { - callback(readError); - return; - } + const json = fs.readFileSync(infile, 'utf8'); + const value = JSON.parse(json); const filename = options.filename || infile; const code = @@ -71,13 +65,7 @@ function transformJSON(infile, options, outfile, callback) { }; } - try { - writeResult(outfile, result); - } catch (writeError) { - callback(writeError); - return; - } - + writeResult(outfile, result); callback(null); } @@ -87,14 +75,8 @@ function transformModule(infile, options, outfile, callback) { return transformJSON(infile, options, outfile, callback); } - let code, transform; - try { - transform = require(options.transform); - code = fs.readFileSync(infile, 'utf8'); - } catch (readError) { - callback(readError); - return; - } + const transform = require(options.transform); + const code = fs.readFileSync(infile, 'utf8'); const variants = options.variants || defaultVariants; const tasks = {}; @@ -136,30 +118,18 @@ function transformModule(infile, options, outfile, callback) { } function optimizeModule(infile, outfile, options, callback) { - let data; - try { - data = JSON.parse(fs.readFileSync(infile, 'utf8')); - } catch (readError) { - callback(readError); - return; - } - + const data = JSON.parse(fs.readFileSync(infile, 'utf8')); const transformed = data.transformed; const result = Object.assign({}, data); result.transformed = {}; const file = data.file; const code = data.code; - try { - Object.keys(transformed).forEach(key => { - result.transformed[key] = optimize(transformed[key], file, code, options); - }); - writeResult(outfile, result); - } catch (error) { - callback(error); - return; - } + Object.keys(transformed).forEach(key => { + result.transformed[key] = optimize(transformed[key], file, code, options); + }); + writeResult(outfile, result); callback(null); }