solargraph icon indicating copy to clipboard operation
solargraph copied to clipboard

documentation requests fail | ArgumentError: invalid empty object name

Open Fire- opened this issue 5 years ago • 7 comments

For several versions now ( I don't have an exact last-working version, unfortunately ) solargraph has thrown an error when attempting to render the documentation page for nearabouts anything. It looks like a blank/nil name is occurring somewhere during the YARD code objects step, but I'm not exactly sure why.

To note, hover hints work fine, as seen in the log below.

Environment

System
	Platform: x86_64-linux-gnu
	Shell:
	Ruby Version: 2.5.1
	RuboCop Version: 0.55.0

Solargraph
	Solargraph Version: 0.39.15
	Core Documentation Version: 2.5.1
	Core Cache Directory: /root/.solargraph/cache
	Parser Target Version: 25
	Using Bundler: true

Project
	Config: {"completion"=>true, "hover"=>true, "symbols"=>true, "definitions"=>true, "rename"=>true, "references"=>true, "autoformat"=>true, "diagnostics"=>true, "formatting"=>true, "folding"=>true, "logLevel"=>"debug", "enablePages"=>true, "viewsPath"=>"/Users/fire/.vscode/extensions/castwide.solargraph-0.21.1/views", "transport"=>"external", "externalServer"=>{"host"=>"127.0.0.1", "port"=>7658}, "commandPath"=>"", "useBundler"=>false, "bundlerPath"=>"docker-compose run --rm solargraph bundle", "checkGemVersion"=>false}
	Workspace folders: ["/Users/fire/projects"]

Debug output:

[INFO]	Server received textDocument/hover
[DEBUG]	{"jsonrpc"=>"2.0", "id"=>16, "method"=>"textDocument/hover", "params"=>{"textDocument"=>{"uri"=>"file:///Users/fire/projects/app/jobs/account_recovery_job.rb"}, "position"=>{"line"=>23, "character"=>22}}}
[INFO]	Cataloging /Users/fire/projects
[INFO]	Catalog complete (722 files, 91566 pins)
[INFO]	Sending response to textDocument/hover
[DEBUG]	Content-Length: 153

	{"jsonrpc":"2.0","id":16,"result":{"contents":{"kind":"markdown","value":"[Aws::SNS::Resource](solargraph:/document?query=Aws%3A%3ASNS%3A%3AResource)"}}}
[INFO]	Server received $/solargraph/document
[DEBUG]	{"jsonrpc"=>"2.0", "id"=>17, "method"=>"$/solargraph/document", "params"=>{"query"=>"Aws::SNS::Resource"}}
[WARN]	Error processing request: [ArgumentError] invalid empty object name
[WARN]	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/yard-0.9.25/lib/yard/code_objects/base.rb:190:in `new'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/api_map/source_to_yard.rb:56:in `block in rake_yard'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/api_map/source_to_yard.rb:51:in `each'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/api_map/source_to_yard.rb:51:in `rake_yard'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/api_map.rb:428:in `document'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/library.rb:265:in `document'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/language_server/host.rb:554:in `block in document'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/language_server/host.rb:554:in `each'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/language_server/host.rb:554:in `document'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/language_server/message/extended/document.rb:9:in `process'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/language_server/host.rb:101:in `receive'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/language_server/transport/adapter.rb:44:in `process'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/language_server/transport/adapter.rb:17:in `block in opening'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/language_server/transport/data_reader.rb:59:in `parse_message_from_buffer'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/language_server/transport/data_reader.rb:35:in `block in receive'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/language_server/transport/data_reader.rb:30:in `each_char'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/language_server/transport/data_reader.rb:30:in `receive'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.39.15/lib/solargraph/language_server/transport/adapter.rb:27:in `receiving'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/backport-1.1.2/lib/backport/client.rb:63:in `tick'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/backport-1.1.2/lib/backport/server/tcpip.rb:76:in `update'
	/usr/lib/ruby/2.5.0/observer.rb:197:in `block in notify_observers'
	/usr/lib/ruby/2.5.0/observer.rb:196:in `each'
	/usr/lib/ruby/2.5.0/observer.rb:196:in `notify_observers'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/backport-1.1.2/lib/backport/client.rb:121:in `read_input'
	/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/backport-1.1.2/lib/backport/client.rb:102:in `block in run_input_thread'
[INFO]	Sending response to $/solargraph/document
[DEBUG]	Content-Length: 103

	{"jsonrpc":"2.0","id":17,"error":{"code":-32603,"message":"[ArgumentError] invalid empty object name"}}

In previous versions I've manually worked around this by injecting a check into solargraph's pin loop so that it straight up skips anything that has a blank name, but that's a bandaid to the real issue ( why are they blank in the first place? ) and I lose those changes every time I update the gem anyway.

Fire- avatar Sep 23 '20 02:09 Fire-

I'm trying to look for a root cause, but I haven't been able to reproduce the error. Do you have an example of code that causes it?

Even if we don't determine a root cause, I expect to include a fix for this in the next patch release. It's safe to say that SourceToYard should never try to create a YARD method object without a name.

castwide avatar Sep 27 '20 10:09 castwide

hmm, honestly I'm not sure I have a reduction that can guarantee it to be triggered - I only have this one ( massive, monolithic, legacy ) project to use this with, so it's kind of a nightmare to figure it out.

I can try to insert some debugging info and see what is being fed in, maybe that'l help nail down what's breaking the whole thing.

Fire- avatar Sep 28 '20 20:09 Fire-

Thanks. Don't worry about it if it's too much trouble, since I'll patch SourceToYard either way.

castwide avatar Sep 29 '20 12:09 castwide

Fixed in version 0.40.0.

castwide avatar Dec 14 '20 10:12 castwide

Hmm, with 0.40.0 I'm still able to replicate.

Even something as simple as

module TestModule
  class MyClass
    def class_def_test!(str)
      puts str
    end
  end
end

triggers the failure - it feels more like something in the environment has broken the entire object store at this point...

Fire- avatar Dec 15 '20 03:12 Fire-

Short version: a hanging comma on the end of an attr_accessor list managed to break, uh, everything?


To try and get some better information, I modified the yard lib itself, from:

https://github.com/lsegal/yard/blob/7104257bef486424d77eddd2f1ffc6834d7ee090/lib/yard/code_objects/base.rb#L189-L190

to

        def new(namespace, name, *args, &block)
          parsargs = method(__method__).parameters.map { |arg| arg[1].to_s }
          raise ArgumentError, "invalid empty object name; #{"Method failed with " + parsargs.map { |arg| "#{arg} = #{eval arg}" }.join(", ")}" if name.to_s.empty?

which gave me something unexpected -

[WARN] Error processing request: [ArgumentError] invalid empty object name; Method failed with namespace = CensoredClass, name = , args = [:instance], block = #<Proc:0x00007f738653e840@/Users/fire/projects/vendor/bundle/ruby/2.5.0/gems/solargraph-0.40.0/lib/solargraph/api_map/source_to_yard.rb:57>

the aforementioned namespace it was failing on is a class that's been functional for years, so it's not like the code itself was broken... however(!), a hanging comma on the class' attr_accessor list caught my eye, so I removed it and solargraph immediately stopped throwing!

Seriously! This crashes:

class CensoredClass
  attr_accessor :attr_one, :attr_two,
#...

Doesn't crash:

class CensoredClass
  attr_accessor :attr_one, :attr_two
#...

And once that's resolved, SG caches the previously-offending object, thus preventing further crashes even if you revert the change for the life of the object cache.

Fire- avatar Dec 15 '20 03:12 Fire-

Hmm. I still can't reproduce this one.

  1. Does this happen with your example code in an otherwise empty workspace, or do you have any bundled/required gems included?

  2. Have you tried running solargraph clear to reset the documentation cache?

castwide avatar Dec 15 '20 05:12 castwide

This bug is no longer reproducible. If you still encounter it, please feel free to reply or open a new issue.

castwide avatar Aug 14 '22 06:08 castwide