Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"A JSON text must at least contain two octets! (JSON::ParserError)" error for npm-based project #30

Closed
ispringer opened this issue May 2, 2018 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ispringer
Copy link

I get the following error when I try to run Licensed on my npm-based project. The error doesn't tell me what JSON file it's trying to parse, so it's pretty hard to diagnose/fix.

$ licensed list
Displaying dependencies for my-ui
  npm dependencies:
/opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/json-1.8.6/lib/json/common.rb:155:in `initialize': A JSON text must at least contain two octets! (JSON::ParserError)
	from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/json-1.8.6/lib/json/common.rb:155:in `new'
	from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/json-1.8.6/lib/json/common.rb:155:in `parse'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/gems/licensed-1.0.1/lib/licensed/source/npm.rb:28:in `dependencies'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/gems/licensed-1.0.1/lib/licensed/command/list.rb:32:in `dependencies'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/gems/licensed-1.0.1/lib/licensed/command/list.rb:18:in `block (3 levels) in run'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/gems/licensed-1.0.1/lib/licensed/command/list.rb:15:in `each'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/gems/licensed-1.0.1/lib/licensed/command/list.rb:15:in `block (2 levels) in run'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/gems/licensed-1.0.1/lib/licensed/command/list.rb:14:in `chdir'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/gems/licensed-1.0.1/lib/licensed/command/list.rb:14:in `block in run'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/gems/licensed-1.0.1/lib/licensed/command/list.rb:12:in `each'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/gems/licensed-1.0.1/lib/licensed/command/list.rb:12:in `run'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/gems/licensed-1.0.1/lib/licensed/cli.rb:48:in `run'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/gems/licensed-1.0.1/lib/licensed/cli.rb:31:in `list'
	from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
	from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
	from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
	from /opt/chefdk/embedded/lib/ruby/gems/2.3.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/gems/licensed-1.0.1/exe/licensed:5:in `<top (required)>'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/bin/licensed:22:in `load'
	from /Users/ips/.chefdk/gem/ruby/2.3.0/bin/licensed:22:in `<main>'
@jonabc
Copy link
Contributor

jonabc commented May 2, 2018

@ispringer thanks for the report!

A more informative error message sounds like a great idea. if you'd like to open a PR fixing this that would be great. Otherwise I'm not sure when I'll have a chance to get to it.

FYI for more short-term investigation purposes, the parsed json comes from npm list --json --production --long

@jonabc jonabc added enhancement New feature or request good first issue Good for newcomers labels May 2, 2018
@ispringer
Copy link
Author

Hi @jonabc,

Thanks for the reply. I ran that command and I got a bunch of errors on stderr. The errors appear to be because my package.json file is actually intended for yarn, and uses some syntax that is not npm-compatible. Note, I was able to parse the JSON from stdout without any errors using JSON.parse via node, so maybe Licensed is trying to parse both stdout+stderr, rather than only stdout, as JSON?

@jonabc
Copy link
Contributor

jonabc commented May 2, 2018

@ispringer Licensed only parses stdout, but intentionally does not use stdout from shell commands that exit with an error code. This avoids picking up information that might be incorrect or out of date if a CLI tool finds an error.

So it sounds like there are two things that would be helpful here

  1. a yarn source that is different from the npm source that is being used
    • it looks like yarn.lock is the indicator that yarn is used in the local directory
  2. a more helpful error message when the npm command fails or output can't be parsed.

I'll open a new issue to create a yarn source to track that request separately.

@mislav
Copy link
Contributor

mislav commented Jun 1, 2018

A friendlier error message from npm (and other shelled-out commands) is now a reality: #38.

@mislav mislav closed this as completed Jun 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants