yarn: no implicit conversion of String into Integer (TypeError)
andreas-hakansson-ingka opened this issue · comments
Hi
We're trying to add Licensed to an existing project that uses yarn
. However, when we try and run licensed cache
we get the following error
yarn
* 0 yarn dependencies
Traceback (most recent call last):
26: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/bin/licensed:23:in `<main>'
25: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/bin/licensed:23:in `load'
24: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/exe/licensed:5:in `<top (required)>'
23: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/thor-1.1.0/lib/thor/base.rb:485:in `start'
22: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
21: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
20: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
19: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/cli.rb:18:in `cache'
18: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/cli.rb:110:in `run'
17: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/commands/command.rb:23:in `run'
16: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/commands/cache.rb:24:in `run_command'
15: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/commands/command.rb:64:in `run_command'
14: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/commands/command.rb:64:in `map'
13: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/commands/command.rb:67:in `block in run_command'
12: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/commands/command.rb:95:in `run_app'
11: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/commands/command.rb:95:in `chdir'
10: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/commands/command.rb:98:in `block in run_app'
9: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/commands/command.rb:98:in `map'
8: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/commands/command.rb:101:in `block (2 levels) in run_app'
7: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/commands/cache.rb:42:in `run_source'
6: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/commands/command.rb:136:in `run_source'
5: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/sources/source.rb:48:in `dependencies'
4: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/sources/source.rb:65:in `cached_dependencies'
3: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/sources/yarn.rb:21:in `enumerate_dependencies'
2: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/sources/yarn.rb:21:in `map'
1: from /__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/sources/yarn.rb:21:in `each'
/__enclose_io_memfs__/lib/ruby/gems/2.6.0/gems/licensed-3.3.1/lib/licensed/sources/yarn.rb:29:in `block in enumerate_dependencies': no implicit conversion of String into Integer (TypeError)
The only thing I can see in sources/yarn.rb that could be causing such as issue, is the version parsing?
$ yarn -v
1.22.17
We've tried it on two different machines
the yarn source file you linked in the master branch won't match the code from the 3.3.1 in the backtrace because the yarn source was recently updated for the next release. the error you're getting is from this line
licensed/lib/licensed/sources/yarn.rb
Line 29 in f6bc82e
Are you using yarn v2 or v3 in your project? The immediate issue that needs to be fixed is the return of []
in all of the guard clauses of dependency_url
, example. When that's returned the []
operator is trying to convert the string to integer for array indexing rather than treating it as a hash map key. I can fix that, and if you need better support for later yarn versions that's also coming in the next release 👍
Oh wow, turns out that I was using an older version (classic) of Yarn on my laptop 😊 Updating solved it and I was able to generate the cache. Thanks!