From 86a2cc23085a756b5855841871d2d75703bf3edf Mon Sep 17 00:00:00 2001 From: Mathew Cormier Date: Thu, 20 Jun 2019 19:03:57 -0400 Subject: [PATCH 1/2] Add a specific error for invalid artifacts --- packages/truffle-compile/profiler.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/truffle-compile/profiler.js b/packages/truffle-compile/profiler.js index 89505d8f1bb..46695c165ff 100644 --- a/packages/truffle-compile/profiler.js +++ b/packages/truffle-compile/profiler.js @@ -71,16 +71,16 @@ module.exports = { "utf8", (err, body) => { if (err) return finished(err); - finished(null, body); + finished(null, { file: buildFile, body }); } ); }, (err, jsonData) => { if (err) return c(err); - try { - for (let i = 0; i < jsonData.length; i++) { - const data = JSON.parse(jsonData[i]); + for (let i = 0; i < jsonData.length; i++) { + try { + const data = JSON.parse(jsonData[i].body); // In case there are artifacts from other source locations. if (sourceFilesArtifacts[data.sourcePath] == null) { @@ -88,9 +88,12 @@ module.exports = { } sourceFilesArtifacts[data.sourcePath].push(data); + } catch (e) { + // JSON.parse throws SyntaxError objects + return e instanceof SyntaxError + ? c(new Error("Invalid artifact: " + jsonData[i].file)) + : c(e); } - } catch (e) { - return c(e); } c(); From e8045317c40a19b6675188efa1558297d6e2b53b Mon Sep 17 00:00:00 2001 From: Mathew Cormier Date: Thu, 27 Jun 2019 12:52:08 -0400 Subject: [PATCH 2/2] New error message --- packages/truffle-compile/profiler.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/truffle-compile/profiler.js b/packages/truffle-compile/profiler.js index 46695c165ff..b5f323740c3 100644 --- a/packages/truffle-compile/profiler.js +++ b/packages/truffle-compile/profiler.js @@ -91,7 +91,11 @@ module.exports = { } catch (e) { // JSON.parse throws SyntaxError objects return e instanceof SyntaxError - ? c(new Error("Invalid artifact: " + jsonData[i].file)) + ? c( + new Error( + "Problem parsing artifact: " + jsonData[i].file + ) + ) : c(e); } }