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

Invalid artifacts error #2118

Merged

Conversation

macor161
Copy link
Contributor

I had this truffle error a few days ago :

Compiling your contracts...
===========================
SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at async.map (/Users/mathew/.nvm/versions/node/v10.15.3/lib/node_modules/truffle/build/webpack:/packages/truffle-compile/profiler.js:83:1)
    at /Users/mathew/.nvm/versions/node/v10.15.3/lib/node_modules/truffle/build/webpack:/packages/truffle-compile/~/async/dist/async.js:1140:1
    at /Users/mathew/.nvm/versions/node/v10.15.3/lib/node_modules/truffle/build/webpack:/packages/truffle-compile/~/async/dist/async.js:473:1
    at iteratorCallback (/Users/mathew/.nvm/versions/node/v10.15.3/lib/node_modules/truffle/build/webpack:/packages/truffle-compile/~/async/dist/async.js:1064:1)
    at /Users/mathew/.nvm/versions/node/v10.15.3/lib/node_modules/truffle/build/webpack:/packages/truffle-compile/~/async/dist/async.js:969:1
    at /Users/mathew/.nvm/versions/node/v10.15.3/lib/node_modules/truffle/build/webpack:/packages/truffle-compile/~/async/dist/async.js:1137:1
    at fs.readFile (/Users/mathew/.nvm/versions/node/v10.15.3/lib/node_modules/truffle/build/webpack:/packages/truffle-compile/profiler.js:74:1)
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)

It turns out that I had an empty JSON artifact file in my build/contracts folder. Truffle tries to parse the file but it is considered to be invalid json.

I thought I must not be the only one to whom this kind of error happens so this is a small pull request to make the message a bit clearer.

You can find a sample project that replicates the error here: https://github.com/macor161/truffle-empty-artifact

@eggplantzzz eggplantzzz added the error better issue indicates improvement to error messaging label Jun 26, 2019
@eggplantzzz
Copy link
Contributor

Thanks for this @macor161, this is helpful for sure! How would you feel about changing the error message for this? I feel like something like "Problem parsing artifact: " might be a bit more accurate. What do you think?

@macor161
Copy link
Contributor Author

Absolutely. Unrelated to the current PR but do you find some of the prettier rules a bit too verbose?
It changed this:

return e instanceof SyntaxError
  ? c(new Error("Problem parsing artifact: " + jsonData[i].file))
  : c(e);

to this:

return e instanceof SyntaxError
  ? c(
      new Error(
        "Problem parsing artifact: " + jsonData[i].file
      )
    )
  : c(e);

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 70.272% when pulling e804531 on macor161:truffle-empty-artifact-error into 83ac203 on trufflesuite:develop.

@eggplantzzz
Copy link
Contributor

Haha, to be honest I'm actually not too big a fan of prettier. I don't like a lot of its formatting but the idea is to use the defaults and eliminate all formatting discussions (which can often use up a lot of energy for very little tangible benefit). Hopefully it saves time, but subjectively I do not like it. Oh well :) I'll get one more set of eyes on this and hopefully we can get it merged in the next day!

Thank you again!

@fainashalts
Copy link
Contributor

+1 LGTM! Thanks for the contribution @macor161!

@eggplantzzz eggplantzzz merged commit c7aa546 into trufflesuite:develop Jun 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
error better issue indicates improvement to error messaging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants