lsegal / yard

YARD is a Ruby Documentation tool. The Y stands for "Yay!"
http://yardoc.org
MIT License
1.94k stars 397 forks source link

NilClass error if markdown provider doesn't exist #501

Closed mitchellh closed 12 years ago

mitchellh commented 12 years ago

I just attempted to parse using Markdown without a Markdown library installed and I get a naster nilclass error. The error is here:

https://github.com/lsegal/yard/blob/master/lib/yard/templates/helpers/html_helper.rb#L65

lsegal commented 12 years ago

Please provide a backtrace with yard --debug

mitchellh commented 12 years ago

Sure thing:


middleware master → bundle exec yard server -r --debug
[debug]: Serving libraries using YARD::Server::WebrickAdapter: middleware
[2012-03-16 20:03:21] INFO  WEBrick 1.3.1
[2012-03-16 20:03:21] INFO  ruby 1.8.7 (2011-06-30) [i686-darwin11.0.1]
[2012-03-16 20:03:21] INFO  WEBrick::HTTPServer#start: pid=9680 port=8808
[debug]: Deserializing /Users/mitchellh/code/personal/ruby/middleware/.yardoc/objects/root.dat...
[debug]: Loading single object DB from .yardoc
[debug]: Deserializing .yardoc/objects/root.dat...
[debug]: Loading single object DB from .yardoc
[debug]: Parsing ["{lib,app}/**/*.rb", "ext/**/*.c"] with `ruby18` parser
[debug]: Processing lib/middleware.rb...
[debug]: Processing lib/middleware/runner.rb...
[debug]: Processing lib/middleware/version.rb...
[info]: File 'lib/middleware/version.rb' was modified, re-processing...
[debug]: Processing lib/middleware/builder.rb...
[info]: File 'lib/middleware/builder.rb' was modified, re-processing...
[debug]: Serializing to .yardoc/objects/root.dat
[error]: Missing 'redcarpet' gem for Markdown formatting. Install it with `gem install redcarpet`
localhost - - [16/Mar/2012:20:03:24 MDT] "GET / HTTP/1.1" 200 4570
- -> /
localhost - - [16/Mar/2012:20:03:24 MDT] "GET /css/custom.css HTTP/1.1" 200 2209
http://localhost:8808/ -> /css/custom.css
localhost - - [16/Mar/2012:20:03:24 MDT] "GET /css/common.css HTTP/1.1" 200 42
http://localhost:8808/ -> /css/common.css
localhost - - [16/Mar/2012:20:03:24 MDT] "GET /js/autocomplete.js HTTP/1.1" 200 8003
http://localhost:8808/ -> /js/autocomplete.js
localhost - - [16/Mar/2012:20:03:24 MDT] "GET /js/app.js HTTP/1.1" 200 6492
http://localhost:8808/ -> /js/app.js
localhost - - [16/Mar/2012:20:03:24 MDT] "GET /css/style.css HTTP/1.1" 200 17034
http://localhost:8808/ -> /css/style.css
localhost - - [16/Mar/2012:20:03:24 MDT] "GET /js/jquery.js HTTP/1.1" 200 85925
http://localhost:8808/ -> /js/jquery.js
localhost - - [16/Mar/2012:20:03:24 MDT] "GET /js/live.js HTTP/1.1" 200 1031
http://localhost:8808/ -> /js/live.js
[debug]: Deserializing /Users/mitchellh/code/personal/ruby/middleware/.yardoc/objects/root.dat...
[debug]: Loading single object DB from .yardoc
[debug]: Deserializing .yardoc/objects/root.dat...
[debug]: Loading single object DB from .yardoc
[debug]: Parsing ["{lib,app}/**/*.rb", "ext/**/*.c"] with `ruby18` parser
[debug]: Processing lib/middleware.rb...
[debug]: Processing lib/middleware/runner.rb...
[debug]: Processing lib/middleware/version.rb...
[debug]: Processing lib/middleware/builder.rb...
[debug]: Serializing to .yardoc/objects/root.dat
[2012-03-16 20:03:26] ERROR NoMethodError: undefined method `new' for nil:NilClass
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/helpers/html_helper.rb:65:in `html_markup_markdown'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/helpers/html_helper.rb:41:in `send'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/helpers/html_helper.rb:41:in `htmlify'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/templates/default/layout/html/setup.rb:49:in `diskfile'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:314:in `send'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:314:in `render_section'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:210:in `run'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:207:in `each'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:207:in `run'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:345:in `add_options'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:206:in `run'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:228:in `yieldall'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:359:in `with_section'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:228:in `yieldall'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/templates/default/layout/html/layout.erb:20:in `_erb_cache_0'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:238:in `send'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:238:in `erb'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:316:in `render_section'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:210:in `run'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:207:in `each'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:207:in `run'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:345:in `add_options'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:206:in `run'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/template.rb:91:in `run'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/templates/engine.rb:88:in `render'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/server/commands/base.rb:143:in `render'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/server/commands/display_file_command.rb:18:in `run'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/server/commands/base.rb:95:in `call'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/server/commands/library_command.rb:49:in `call'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/server/router.rb:135:in `route_docs'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/server/router.rb:110:in `route'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/server/router.rb:54:in `call'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/server/webrick_adapter.rb:28:in `do_GET'
    /Users/mitchellh/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/httpservlet/abstract.rb:35:in `__send__'
    /Users/mitchellh/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/httpservlet/abstract.rb:35:in `service'
    /Users/mitchellh/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    /Users/mitchellh/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    /Users/mitchellh/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    /Users/mitchellh/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:162:in `start'
    /Users/mitchellh/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    /Users/mitchellh/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:95:in `start'
    /Users/mitchellh/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:92:in `each'
    /Users/mitchellh/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:92:in `start'
    /Users/mitchellh/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:23:in `start'
    /Users/mitchellh/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/webrick/server.rb:82:in `start'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/server/webrick_adapter.rb:14:in `start'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/cli/server.rb:44:in `run'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/cli/command.rb:13:in `run'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/cli/command_parser.rb:68:in `run'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/lib/yard/cli/command_parser.rb:50:in `run'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/gems/yard-0.7.5/bin/yard:4
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/bin/yard:19:in `load'
    /Users/mitchellh/.rvm/gems/ruby-1.8.7-p352/bin/yard:19
lsegal commented 12 years ago

Ah, this is not really a bug. The error is listed in your output warning you of impending problems. The alternative would just be to exit early, but yard server can't do that, because it doesn't necessarily know what it is serving at load time (that error only actually pops up when you make a request, I believe). We could add better checks in the server to catch exceptions and display them in a nicer fashion, but it wouldn't fix the underlying problem.

mitchellh commented 12 years ago

I suppose the "bug" I had was that a stack trace was thrown. In general I consider a stack trace thrown out of any tool to be a bug. But however you like to look at it is is fine.

lsegal commented 12 years ago

I'm not too concerned with the stack trace being thrown (we actually display stack traces often with --backtrace). The only issue is that it's being thrown in the wrong place, but that's kind of a low priority issue right now.