Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Add a specific error for invalid artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
macor161 committed Jun 20, 2019
1 parent acba61b commit 86a2cc2
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/truffle-compile/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,29 @@ 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) {
sourceFilesArtifacts[data.sourcePath] = [];
}

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();
Expand Down

0 comments on commit 86a2cc2

Please sign in to comment.