pygments / pygments.rb

💎 Ruby wrapper for Pygments syntax highlighter
MIT License
572 stars 141 forks source link

Pygments.highlight returning nil #78

Closed johncblandii closed 3 years ago

johncblandii commented 11 years ago

I've tried running this directly to no avail and through Jekyll [where nil is shown].

ruby -e "require 'pygments'; puts Pygments.css('.highlight')"

Returns just an empty line. When I run Jekyll I get the 'nil' error:

~/workspaces/web-skin (master): jekyll serve
Configuration file: /Users/johnbland/workspaces/web-skin/_config.yml
            Source: ./static
       Destination: ./style-guide
      Generating...   Liquid Exception: undefined method `sub' for nil:NilClass in components.html
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/tags/highlight.rb:77:in `add_code_tags'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/tags/highlight.rb:56:in `render_pygments'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/tags/highlight.rb:45:in `render'
~/.rvm/gems/ruby-2.0.0-p195/gems/liquid-2.5.0/lib/liquid/block.rb:106:in `block in render_all'
~/.rvm/gems/ruby-2.0.0-p195/gems/liquid-2.5.0/lib/liquid/block.rb:93:in `each'
~/.rvm/gems/ruby-2.0.0-p195/gems/liquid-2.5.0/lib/liquid/block.rb:93:in `render_all'
~/.rvm/gems/ruby-2.0.0-p195/gems/liquid-2.5.0/lib/liquid/block.rb:82:in `render'
~/.rvm/gems/ruby-2.0.0-p195/gems/liquid-2.5.0/lib/liquid/template.rb:124:in `render'
~/.rvm/gems/ruby-2.0.0-p195/gems/liquid-2.5.0/lib/liquid/template.rb:132:in `render!'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/convertible.rb:77:in `render_liquid'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/convertible.rb:128:in `do_layout'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/page.rb:111:in `render'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/site.rb:235:in `block in render'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/site.rb:233:in `each'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/site.rb:233:in `render'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/site.rb:44:in `process'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/command.rb:18:in `process_site'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/commands/build.rb:23:in `build'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/lib/jekyll/commands/build.rb:7:in `process'
~/.rvm/gems/ruby-2.0.0-p195/gems/jekyll-1.0.2/bin/jekyll:83:in `block (2 levels) in <top (required)>'
~/.rvm/gems/ruby-2.0.0-p195/gems/commander-4.1.3/lib/commander/command.rb:180:in `call'
~/.rvm/gems/ruby-2.0.0-p195/gems/commander-4.1.3/lib/commander/command.rb:180:in `call'
~/.rvm/gems/ruby-2.0.0-p195/gems/commander-4.1.3/lib/commander/command.rb:155:in `run'
~/.rvm/gems/ruby-2.0.0-p195/gems/commander-4.1.3/lib/commander/runner.rb:402:in `run_active_command'
~/.rvm/gems/ruby-2.0.0-p195/gems/commander-4.1.3/lib/commander/runner.rb:66:in `run!'
~/.rvm/gems/ruby-2.0.0-p195/gems/commander-4.1.3/lib/commander/delegates.rb:7:in `run!'
~/.rvm/gems/ruby-2.0.0-p195/gems/commander-4.1.3/lib/commander/import.rb:10:in `block in <top (required)>'
johncblandii commented 11 years ago

Bump.

FranklinChen commented 11 years ago

I was getting this also, and found out what the problem was, once I read the source, found popen.rb, and and set the MENTOS_LOG environment variable: my machine was under heavy load from a background process and mentos timed out. I simply edited my copy of popen.rb in my installed gems directory to increase timeout_time to a big number, and then pygments.rb worked again.

bluesmoon commented 10 years ago

I see the same problem. My system is not under any load at all.

FranklinChen commented 10 years ago

https://github.com/tmm1/pygments.rb/commit/e0ed7f73f03aa59680b469f4f26e208d3cf8d999 allows you to bypass the timeout problem that I wrote about in http://conscientiousprogrammer.com/blog/2013/06/29/nil-non-determinism-exceptions/

stomar commented 10 years ago

We've got the same problem when generating the "Jekyll powered" www.ruby-lang.org site (with over one thousand highlighted code snippets).

I've seen failing site builds with meaningless error messages for quite a long time on my (a little aged) machine, but did not investigate further. Since yesterday we let Travis test the builds, and already the third or fourth build failed, see https://github.com/ruby/www.ruby-lang.org/pull/682.

It took me quite some time to trace the problem down to Pygments and its unexpected (and not documented) timeout behaviour.

Increasing MENTOS_TIMEOUT is a solution that offers itself only to the users that are aware of the actual problem. So please consider changing this completely unexpected (= exceptional...) behaviour of returning nil into something more easily to debug.

stomar commented 10 years ago

Jekyll is going to deal with the unexpected return value on their side, see https://github.com/jekyll/jekyll/pull/2148. I still think the exception should be raised by Pygments itself, though...

cc @FranklinChen