Np: Better exception for wrong project folder

Created on 27 Nov 2016  路  3Comments  路  Source: sindresorhus/np

When running np in a project without package.json it throws a cryptic error: Cannot read property 'version' of undefined.

I propose two things:

  • Coming up with a more descriptive error message along the lines of No package.json found, are you in the right project?.
  • Reading the package.json file once, and and validating that there is one before passing it to the ui and index files.

I have a PR ready to send to address this but I'd like to sign off on the correct error message first, or if this is even worth pursuing :)

enhancement help wanted

Most helpful comment

Solution 1 looks good to me.

All 3 comments

Solution 1 looks good to me.

My proposal was actually two-fold, I'd like to prevent implementing the undefined check in multiple places, since currently readPkgUp.sync().pkg is called in both ui.js and index.js separately.

Is there a particular reason for that?

Oh ok, missed that. Was on my mobile device so difficult to catch that :).

You are right, I think it would make more sense to read the pkg once in cli.js and pass it downstream to the UI and to np. Feel free to send the PR :).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ProfessorManhattan picture ProfessorManhattan  路  4Comments

sindresorhus picture sindresorhus  路  4Comments

inker picture inker  路  4Comments

fregante picture fregante  路  5Comments

kapooostin picture kapooostin  路  5Comments