Error when parsing `Foo::Bar = -> {}`
lamorrison opened this issue · 2 comments
Description
When adding Packwerk to an existing project an error was thrown during packwerk check
.
This seems to be due to a namespaced constant which is assigned a lambda expression, like Foo::Bar = -> {}
.
A mitigation is to exclude the offending file in packwerk.yml
so that the rest of the codebase can be analysed as usual. However it's not obvious which file was being processed when the error occurred.
To Reproduce
Add a namespaced constant which is assigned a lambda expression to any file which Packwerk parses, for example:
# foo.rb
Foo::Bar = -> {}
Then run bundle exec packwerk check
as usual.
Expected Behaviour
Packwerk should parse and analyse the lambda expression like any other code block.
Screenshots
/Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node.rb:224:in `type_of': undefined method `type' for nil:NilClass (NoMethodError)
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node.rb:101:in `constant?'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node.rb:267:in `module_creation?'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node.rb:163:in `module_name_from_definition'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/const_node_inspector.rb:43:in `constant_in_module_or_class_definition?'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:161:in `call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:161:in `validate_call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:90:in `block in create_validator_slow'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/const_node_inspector.rb:23:in `constant_name_from_node'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:161:in `call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:161:in `validate_call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:90:in `block in create_validator_slow'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/reference_extractor.rb:33:in `block in reference_from_node'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/reference_extractor.rb:32:in `each'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/reference_extractor.rb:32:in `reference_from_node'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node_processor.rb:28:in `call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation_2_6.rb:764:in `call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation_2_6.rb:764:in `block in create_validator_method_medium2'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node_visitor.rb:12:in `visit'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node_visitor.rb:17:in `block in visit'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node.rb:63:in `block in each_child'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node.rb:62:in `each'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node.rb:62:in `each_child'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node_visitor.rb:16:in `visit'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node_visitor.rb:17:in `block in visit'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node.rb:63:in `block in each_child'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node.rb:62:in `each'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node.rb:62:in `each_child'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/node_visitor.rb:16:in `visit'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/file_processor.rb:49:in `references_from_ast'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/file_processor.rb:37:in `call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation_2_6.rb:703:in `call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation_2_6.rb:703:in `block in create_validator_method_medium1'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/run_context.rb:56:in `process_file'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:161:in `call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:161:in `validate_call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:90:in `block in create_validator_slow'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/parse_run.rb:66:in `block in find_offenses'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/parallel-1.21.0/lib/parallel.rb:515:in `call_with_index'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/parallel-1.21.0/lib/parallel.rb:485:in `process_incoming_jobs'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/parallel-1.21.0/lib/parallel.rb:465:in `block in worker'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/parallel-1.21.0/lib/parallel.rb:456:in `fork'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/parallel-1.21.0/lib/parallel.rb:456:in `worker'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/parallel-1.21.0/lib/parallel.rb:447:in `block in create_workers'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/parallel-1.21.0/lib/parallel.rb:446:in `each'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/parallel-1.21.0/lib/parallel.rb:446:in `each_with_index'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/parallel-1.21.0/lib/parallel.rb:446:in `create_workers'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/parallel-1.21.0/lib/parallel.rb:386:in `work_in_processes'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/parallel-1.21.0/lib/parallel.rb:289:in `map'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/parallel-1.21.0/lib/parallel.rb:302:in `flat_map'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/parse_run.rb:74:in `block in find_offenses'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/parse_run.rb:72:in `find_offenses'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/parse_run.rb:45:in `check'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/cli.rb:53:in `execute_command'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:161:in `call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:161:in `validate_call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/_methods.rb:270:in `block in _on_method_added'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/lib/packwerk/cli.rb:40:in `run'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:161:in `call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/call_validation.rb:161:in `validate_call'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/sorbet-runtime-0.5.9464/lib/types/private/methods/_methods.rb:270:in `block in _on_method_added'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/packwerk-2.0.0/exe/packwerk:12:in `<top (required)>'
from /Users/me/.asdf/installs/ruby/2.6.9/bin/packwerk:23:in `load'
from /Users/me/.asdf/installs/ruby/2.6.9/bin/packwerk:23:in `<top (required)>'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/lib/bundler/cli/exec.rb:58:in `load'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/lib/bundler/cli/exec.rb:58:in `kernel_load'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/lib/bundler/cli/exec.rb:23:in `run'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/lib/bundler/cli.rb:478:in `exec'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/lib/bundler/cli.rb:31:in `dispatch'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/lib/bundler/cli.rb:25:in `start'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/exe/bundle:49:in `block in <top (required)>'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/lib/bundler/friendly_errors.rb:103:in `with_friendly_errors'
from /Users/me/.asdf/installs/ruby/2.6.9/lib/ruby/gems/2.6.0/gems/bundler-2.2.32/exe/bundle:37:in `<top (required)>'
from /Users/me/.asdf/installs/ruby/2.6.9/bin/bundle:23:in `load'
from /Users/me/.asdf/installs/ruby/2.6.9/bin/bundle:23:in `<main>'
Version Information
- Packwerk: v2.0.0
- Ruby: v2.6.9
- Bundler: v2.2.32
- Asdf: v0.8.1
Additional Context
A constant which isn't namespaced, like Foo = -> {}
seems to be fine. Using Foo:Bar = Proc.new {}
seems to be fine.
It would be helpful if a parsing error included the name of the file being parsed.
That looks like a bug for sure.
Thank you for the detailed bug report, @lamorrison .