Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Conversation

JoshuaKGoldberg
Copy link
Contributor

Fixes #19628

Instead of the direct JSON.parse error, this gives a warning mentioning the file name.

image

@JoshuaKGoldberg JoshuaKGoldberg requested a review from a team as a code owner January 17, 2018 22:54
@zkat
Copy link
Contributor

zkat commented Mar 6, 2018

We should not be skipping pkglocks if they fail to parse -- I think a better patch here is to go into lib/utils/parse-json.js and make it use json-parse-better-errors, which is what we use in other parts of the CLI to output more informative parse errors.

Could you send that patch in, instead? You'll have to rewrite this anyway, because npm@5.7.0 added support for automatic git conflict resolution for pkglocks, so this code is a bit different now.

@JoshuaKGoldberg
Copy link
Contributor Author

json-parse-better-errors

Adding a new package dependency wasn't something I was planning on doing for my first npm contribution, but cool!

@zkat
Copy link
Contributor

zkat commented Mar 6, 2018

@JoshuaKGoldberg it's not -quite- a new dependency. It's used a lot by npm's deps and I guess I'm actually surprised we don't have it as a toplevel dependency. Just make sure it's in bundleDependencies, too!

@zkat zkat changed the base branch from latest to release-next March 7, 2018 21:41
Copy link
Contributor

@zkat zkat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks a bunch! 🎉

@zkat
Copy link
Contributor

zkat commented Mar 7, 2018

➜ npm i
npm ERR! Unexpected token { in JSON at position 104 while parsing near '...e,
npm ERR!   "dependencies" {
npm ERR!     "eggplant": {
npm ERR! ...'

I think this is a much nicer error (could be better, but better than "uh idk")

@zkat zkat merged commit ae7132d into npm:release-next Mar 8, 2018
@JoshuaKGoldberg JoshuaKGoldberg deleted the fix/invalid-shrinkwrap-json branch March 8, 2018 15:31
zkat pushed a commit that referenced this pull request Mar 8, 2018
* Used json-parse-better-errors in parse-json.js

* Added json-parse-better-errors to bundleDependencies

PR-URL: #19629
Credit: @JoshuaKGoldberg
Reviewed-By: @zkat
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants