xwmx / pandoc-ruby

Ruby wrapper for Pandoc
MIT License
340 stars 43 forks source link

Raise error if pandoc does not return success (requires ruby 1.9.3+) #10

Closed candlerb closed 9 years ago

candlerb commented 10 years ago

At the moment if pandoc fails (e.g. you pass invalid options) then pandoc-ruby silently returns an empty string with no indication of the error. This patch detects the return code and raises an error if it is non-zero.

$ irb20 -Ilib
irb(main):001:0> require 'pandoc-ruby'
=> true
irb(main):002:0> PandocRuby.new("# hello", "badopt").to_html5
RuntimeError: pandoc: unrecognized option `--badopt'
Try pandoc --help for more information.

    from /Users/brian/git/pandoc-ruby/lib/pandoc-ruby.rb:219:in `execute'
    from /Users/brian/git/pandoc-ruby/lib/pandoc-ruby.rb:201:in `convert_string'
    from /Users/brian/git/pandoc-ruby/lib/pandoc-ruby.rb:135:in `convert'
    from /Users/brian/git/pandoc-ruby/lib/pandoc-ruby.rb:169:in `block (2 levels) in <class:PandocRuby>'
    from (irb):2
    from /usr/local/bin/irb20:12:in `<main>'
xwmx commented 10 years ago

@candlerb Thanks for the patch, and sorry I haven't had a chance to get to this yet. The main two things on my mind are that I'd want to add tests for this change and I'm worried about dropping 1.8 support since it's a small library and I don't want to exclude people as was the issue in #9

I'll think about this a little more as soon as I can.

candlerb commented 10 years ago

No problem. I did try using $? after open3 but it didn't seem to give the right result code consistently.

davepwsmith commented 10 years ago

I think some sort of error handling is necessary really though. I spent a good 45 minutes racking my brains for complicated reasons that this wasn't working a few days ago until I realised that I had made a typo in one of the pandoc arguments calling for a .bib file that didn't exist, and pandoc-ruby was just failing silently and not ouputting any html to the files I was trying to create! Are there really many people still using 1.8.x versions of Ruby? Even OSX now ships with 1.9.x...

xwmx commented 10 years ago

@davepwsmith Ugh. Sorry about that. You are absolutely right. It's been almost a year since 1.8 was EOL, so it's time to revisit this.

xwmx commented 9 years ago

This is finally available in the current version on RubyGems (1.0.0) and the minimum supported Ruby version is now 1.9.3. Sorry for the delay and thanks for the fix!