Repository navigation
Open
Description
I'm having a strange error when running yardstick on my code base. It's been running fine for quite a while now, and has been really helpful in getting my documentation quality up, so I'd love to figure out what's gone wrong. Unfortunately, pecking through the code I can't seem to make heads or tails of what's gone wrong.
Running Ruby 1.9.2 (installed via RVM). The project is available here, and the current Git HEAD is precisely the set of code that's causing this error, if it would help to run things yourself. I can duplicate the error on two machines (with Ruby 1.9.2 and Yardstick 0.4.0), so I don't think it's a problem with my machine or Ruby setup.
Let me know if there's anything else I can do to help!
Backtrace follows:
[cpence@bertrand ~/Development/rletters/master]$ yardstick 'app/**/*.rb' 'lib/**/*.rb'
/Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/method.rb:94:in `visibility': undefined method `visibility' for nil:NilClass (NoMethodError)
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/method.rb:36:in `block in <module:Method>'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/measurement.rb:143:in `instance_eval'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/measurement.rb:143:in `block in measure'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/measurement.rb:142:in `catch'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/measurement.rb:142:in `measure'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/measurement.rb:36:in `initialize'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/rule.rb:31:in `new'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/rule.rb:31:in `measure'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/rule_set.rb:14:in `block in measure'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/ordered_set.rb:64:in `each'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/ordered_set.rb:64:in `each'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/rule_set.rb:14:in `map'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/rule_set.rb:14:in `measure'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/measurable.rb:74:in `measure'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/processor.rb:41:in `block in measurements'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/processor.rb:40:in `each'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/processor.rb:40:in `measurements'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/processor.rb:15:in `process_path'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick.rb:23:in `measure'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/lib/yardstick/cli.rb:19:in `run'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/gems/yardstick-0.4.0/bin/yardstick:7:in `<top (required)>'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/bin/yardstick:21:in `load'
from /Users/cpence/.rvm/gems/ruby-1.9.2-p290/bin/yardstick:21:in `<main>'
Metadata
Metadata
Assignees
Labels
No labels
Activity
dkubb commentedon Sep 28, 2011
Just from the stacktrace it looks like the error is happening within the Yardstick::Method module, which is mixed into
YARD::CodeObjects::MethodObject. It uses theobject.visibilityfrom that MethodObject, and it looks likeobjectis nil.I'll try running the code against your repo later on. In the meantime, you could try running it against parts of the source code until you narrow down which file the problem is happening with. The most likely problem is that YARD has a bug in it's parser and is being tripped up by something specific in one place within the source.
cpence commentedon Sep 29, 2011
Should have thought of that. It's the app/models/document.rb file. In particular, it seems to be the following snippet:
Remove the docstring on only one of these, and it still crashes. Remove both docstrings, and it works. Can you spot anything obviously crazy here?
dkubb commentedon Sep 29, 2011
Hmm. Nothing obvious stands out for me. Sometimes when there are parsing errors (not just YARD, but in general I've noticed) the error could actually be above wherever the problem is manifesting. Like for example, maybe there's something that put the parser in an invalid state above this code.
What I might start by doing is a kind of binary search; removing all of the docs from the halfway mark down, see if the problem stays or goes away, and then keep dividing the doc up until you zero in on it.
cpence commentedon Oct 2, 2011
Okay, I've pruned it down to a minimal example and posted it here.
It seems that YARD/Yardstick doesn't like
cattr_reader. If I change thecattr_readerin both of these toattr_reader, everything parses just fine. Is there something I need to do to add support for Rails'scattr_readerto the YARD parser or to Yardstick?dkubb commentedon Oct 2, 2011
@cpence: it wouldn't be anything to do with Yardstick, but YARD itself. What you want to do is write a YARD handler that identifies the
cattr_readercall and relates that to the method it defines. Its actually not that difficult, it's probably around 10-15 loc in the core, and then a bit of supporting mostly boilerplate code to package it up into a gem.Here's two examples of YARD handlers, but you may be able to find more through github/google search:
https://github.com/postmodern/yard-dm-is-predefined
https://github.com/postmodern/yard-dm
By itself YARD has no knowledge of DSL methods like
cattr_readerand the method definition side effect. The handler allows you treat those DSL methods as if they were inline method definitions, eg:https://github.com/postmodern/yard-dm/blob/master/lib/yard-dm/belongs_to_handler.rb
dkubb commentedon Oct 2, 2011
@cpence: it wouldn't be anything to do with Yardstick, but YARD itself. What you want to do is write a YARD handler that identifies the
cattr_readercall and relates that to the method it defines. Its actually not that difficult, it's probably around 10-15 loc in the core, and then a bit of supporting mostly boilerplate code to package it up into a gem.Here's two examples of YARD handlers, but you may be able to find more through github/google search:
https://github.com/postmodern/yard-dm-is-predefined
https://github.com/postmodern/yard-dm
By itself YARD has no knowledge of DSL methods like
cattr_readerand the method definition side effect. The handler allows you treat those DSL methods as if they were inline method definitions, eg:https://github.com/postmodern/yard-dm/blob/master/lib/yard-dm/belongs_to_handler.rb
dkubb commentedon Oct 2, 2011
I'm going to keep this ticket open though because it looks like I need to handle cases where YARD is parsing what looks to be like a method's documentation, but it doesn't know which method to associate the docs with.
cpence commentedon Oct 2, 2011
Awesome, thanks for the help on this. And agreed that there should be some way for Yardstick to recover when it can -- or at least print a pretty error message.
cpence commentedon Oct 2, 2011
A related point that does pertain only to Yardstick: now that I have a functioning DSL handler for
cattr_*, how do I get Yardstick to load it? Is there a way (similar to YARD's-eoption) to specify an extension to load, since it's not packaged as a gem?RichMorin commentedon Dec 29, 2011
I'm getting the same error from Yardstick (0.0.1), with no complaint from YARD (0.7.4).
Here's the code: http://pastie.org/3087569