Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on Ruby 1.9.3 #167

Closed
Stwissel opened this issue Mar 14, 2014 · 24 comments
Closed

Error on Ruby 1.9.3 #167

Stwissel opened this issue Mar 14, 2014 · 24 comments

Comments

@Stwissel
Copy link

Installed mustache using

$ sudo gem install
$ mustache --version
Mustache v0.99.5

Executing:

$ cat test.yml test.mustache | mustache

I get the error:

/var/lib/gems/1.9.1/gems/mustache-0.99.5/bin/mustache:76:in `process_files': undefined method `each_document' for Psych:Module (NoMethodError)
    from /var/lib/gems/1.9.1/gems/mustache-0.99.5/bin/mustache:93:in `<top (required)>'
    from /usr/local/bin/mustache:23:in `load'
    from /usr/local/bin/mustache:23:in `<main>'

For the combined file


---
Peter :Demo
Demo : XXX

---
CREATE DATABASE {{Peter}};
CREATE TABLE {{Demo}};

Ruby:

 ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

What do I miss?

@locks
Copy link
Member

locks commented Mar 14, 2014

Hm, I'm not sure what might be the problem. Maybe the wrong version of Psych?
I tried replicating with ruby 1.9.3p286 (2012-10-12 revision 37165) [x86_64-darwin12.3.0] but was unable to.

@Stwissel
Copy link
Author

Hi Ricardo,

Thx for looking into this. I'm still on Ubuntu 12.10 which is Ruby 1.9.1
Guess I have to learn how to install an older version of mustache

On Friday, 14 March 2014, Ricardo Mendes notifications@github.com wrote:

Hm, I'm not sure what might be the problem. Maybe the wrong version of
Psych?
I tried replicating with ruby 1.9.3p286 (2012-10-12 revision 37165)
[x86_64-darwin12.3.0] but was unable to.


Reply to this email directly or view it on GitHubhttps://github.com//issues/167#issuecomment-37642866
.

Create a nice day!
Stephan H. Wissel

Phone: +65 96673269
Blog http://www.wissel.net/blog Twitter http://twitter.com/notessensei
Google+ https://plus.google.com/114116118906495091782/about
Facebookhttp://www.facebook.com/stephan.wissel
LinkedIn http://sg.linkedin.com/in/notessensei
Xinghttps://www.xing.com/profile/StephanH_Wissel
Sametime http://www.wissel.net/blog/d6plinks/SHWL-84KE8U Skype

@sagotch
Copy link

sagotch commented Apr 7, 2014

Hi.

Same problem here, did you fix this issue?

$ mustache --version
Mustache v0.99.5
$ ruby --version
ruby 2.1.0p0 (2013-12-25 revision 44422) [i686-linux]

@bfontaine
Copy link

In Ruby 1.9.3, the default YAML parser switched from Syck to Psych. Syck provides each_document, but not Psych, and this cause this error. The following piece of code:

require 'yaml'

doesn’t require the same module in Ruby <1.9 and Ruby >=1.9. From the docs:

Syck was the original for YAML implementation in Ruby’s standard library developed by why the lucky stiff.

If you prefer, you can still use Syck by changing the YAML::ENGINE like so:

YAML::ENGINE.yamler = 'syck'
# switch back to the default Psych
YAML::ENGINE.yamler = 'psych'

In older Ruby versions, ie. <= 1.9, Syck is still provided, however it was completely removed with the release of Ruby 2.0.0.

Mustache takes care of this issue, as we can see in the code, but this was committed after the last release of the gem, which occurred 3 years ago. So the solution is to install it from source. Add the following to your Gemfile:

gem 'mustache', :git => 'git://github.com/defunkt/mustache.git'

Then use bundle install and it’ll work!

If you don’t use Bundler or want to install the gem globally, clone the repo and install the gem from it:

git clone https://github.com/defunkt/mustache.git
cd mustache
gem build mustache.gemspec
gem install ./mustache-0.99.5.gem

@sagotch
Copy link

sagotch commented Apr 8, 2014

Install from sources worked for me 👍

@locks
Copy link
Member

locks commented Apr 17, 2014

Thank you for the insightful post @bfontaine. I'm closing this issue since it appears to be fixed in master, and continue work on the 0.99.6 release.

@locks locks closed this as completed Apr 17, 2014
@Stwissel
Copy link
Author

Installed it from source, updated Ruby, didn't work:

       ruby --version
       ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]

       mustache --version
       Mustache v0.99.5

       $ cat testcombined.mustache | mustache    

and the error is:

/home/stw/.rvm/gems/ruby-2.1.1/gems/mustache-0.99.5/bin/mustache:78:in `read': no implicit conversion of nil into String (TypeError)
    from /home/stw/.rvm/gems/ruby-2.1.1/gems/mustache-0.99.5/bin/mustache:78:in `process_files'
    from /home/stw/.rvm/gems/ruby-2.1.1/gems/mustache-0.99.5/bin/mustache:109:in `'
    from /home/stw/.rvm/gems/ruby-2.1.1/bin/mustache:23:in `load'
    from /home/stw/.rvm/gems/ruby-2.1.1/bin/mustache:23:in `'
    from /home/stw/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
    from /home/stw/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `'

so something is still amiss

@locks
Copy link
Member

locks commented Apr 17, 2014

@Stwissel 2.1.1p76 != 1.9.3, one step at a time :P

@Stwissel
Copy link
Author

Ok - sorry. Forgot to mention what I did:

  1. Installed Mustache from source
  2. Tried with ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
    -> Get the error:
    /var/lib/gems/1.9.1/gems/mustache-0.99.5/bin/mustache:78:in `read': can't convert nil into String (TypeError)
    from /var/lib/gems/1.9.1/gems/mustache-0.99.5/bin/mustache:78:in`process_files'
    from /var/lib/gems/1.9.1/gems/mustache-0.99.5/bin/mustache:109:in `'
    from /usr/local/bin/mustache:23:in`load'
    from /usr/local/bin/mustache:23:in `
    
  3. Install ruby 2.1.1
  4. Install mustache from source again
  5. Test and get above error

@locks
Copy link
Member

locks commented Apr 17, 2014

@Stwissel I seem to have introduced that bug by merging #169 in d6f9d79, apologies.
I'll try to sort it out.

locks pushed a commit that referenced this issue Apr 17, 2014
@locks
Copy link
Member

locks commented Apr 17, 2014

@Stwissel can you give it another go?

@Stwissel
Copy link
Author

Just (30 min ago) pulled from github and reinstalled mustache:

stw@ubuntu:~/tests$ ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
stw@ubuntu:~/tests$ cat test.mustache | mustache 
/usr/lib/ruby/1.9.1/psych.rb:206:in `parse': (): mapping values are not allowed in this context at line 3 column 6 (Psych::SyntaxError)
    from /usr/lib/ruby/1.9.1/psych.rb:206:in `parse_stream'
    from /usr/lib/ruby/1.9.1/psych.rb:289:in `load_stream'
    from /var/lib/gems/1.9.1/gems/mustache-0.99.5/bin/mustache:82:in `process_files'
    from /var/lib/gems/1.9.1/gems/mustache-0.99.5/bin/mustache:111:in `'
    from /usr/local/bin/mustache:23:in `load'
    from /usr/local/bin/mustache:23:in `'

and on newer ruby:

stw@ubuntu:~/tests$ ruby --version
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
stw@ubuntu:~/tests$ cat test.mustache | mustache
/home/stw/.rvm/gems/ruby-2.1.1/gems/mustache-0.99.5/bin/mustache:78:in `read': no implicit conversion of nil into String (TypeError)
    from /home/stw/.rvm/gems/ruby-2.1.1/gems/mustache-0.99.5/bin/mustache:78:in `process_files'
    from /home/stw/.rvm/gems/ruby-2.1.1/gems/mustache-0.99.5/bin/mustache:109:in `'
    from /home/stw/.rvm/gems/ruby-2.1.1/bin/mustache:23:in `load'
    from /home/stw/.rvm/gems/ruby-2.1.1/bin/mustache:23:in `'
    from /home/stw/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `eval'
    from /home/stw/.rvm/gems/ruby-2.1.1/bin/ruby_executable_hooks:15:in `'

@Stwissel
Copy link
Author

Upps... sorry - last test was wrong. Forgot to reinstall the gem in Ruby 2.1.1. Works like a charm now. So - fixed. You just need to specify in the upcoming gem definition that you need ruby 2.x

@k-bx
Copy link

k-bx commented Sep 11, 2014

Just FYI, issue is present on Ubuntu 14.04 if you apt-get install ruby-mustache. I think it's quite important to keep mustache usable from apt-get.

Thanks!

@Stwissel
Copy link
Author

I just did apt-get install mustache and it worked

On Friday, 12 September 2014, Konstantine Rybnikov notifications@github.com
wrote:

Just FYI, issue is present on Ubuntu 14.04 if you apt-get install
ruby-mustache. I think it's quite important to keep mustache usable from
apt-get.

Thanks!


Reply to this email directly or view it on GitHub
#167 (comment).

Create a nice day!
Stephan H. Wissel

Phone: +65 96673269
Blog http://www.wissel.net/blog Twitter http://twitter.com/notessensei
Google+ https://plus.google.com/114116118906495091782/about Facebook
http://www.facebook.com/stephan.wissel LinkedIn
http://sg.linkedin.com/in/notessensei Xing
https://www.xing.com/profile/StephanH_Wissel Sametime
http://www.wissel.net/blog/d6plinks/SHWL-84KE8U Skype

@k-bx
Copy link

k-bx commented Sep 12, 2014

@Stwissel just tried on my own Ubuntu 14.04 (previously tried on server), same error:

➜  tmp  cat ./tpl.yaml 
---
foo: "bar"
---
➜  tmp  cat ./tpl.mustache 
Hello, {{foo}}
➜  tmp  mustache ./tpl.yaml ./tpl.mustache
/usr/bin/mustache:76:in `process_files': undefined method `each_document' for Psych:Module (NoMethodError)
        from /usr/bin/mustache:93:in `<main>'

@k-bx
Copy link

k-bx commented Sep 12, 2014

@Stwissel reproduced inside fresh docker image http://paste.ubuntu.com/8326823/

@locks
Copy link
Member

locks commented Sep 12, 2014

That paste is a bit confusing, is the system ruby 1.9.3 or 1.9.1?

@k-bx
Copy link

k-bx commented Sep 12, 2014

@locks what's confusing? It should be reproduceable on any linux with docker installed and ~/tmp/tpl.yaml and ~/tmp/tpl.mustache preserved. You can omit -v option to share directories between host and guest, and write yaml/mustache files by hands if you want to.

Maybe this is more clear:

➜  ~  sudo docker run -t -i --rm ubuntu:14.04 /bin/bash
root@ba1c53a632c0:/# apt-get update -qq && apt-get install -qq ruby-mustache > /dev/null
root@ba1c53a632c0:/# echo $'---\nfoo: "bar"\n---\n' > tpl.yaml
root@ba1c53a632c0:/# cat tpl.yaml
---
foo: "bar"
---

root@ba1c53a632c0:/# echo $'Hello, {{foo}}' > tpl.mustache
root@ba1c53a632c0:/# cat tpl.mustache 
Hello, {{foo}}
root@ba1c53a632c0:/# mustache ./tpl.yaml ./tpl.mustache 
/usr/bin/mustache:76:in `process_files': undefined method `each_document' for Psych:Module (NoMethodError)
        from /usr/bin/mustache:93:in `<main>'
root@ba1c53a632c0:/# ruby --version
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

You can see ruby version also.

@locks
Copy link
Member

locks commented Sep 16, 2014

@k-bx I'm not familiar with Ubuntu/etc, but I just tried installing ruby-mustache in a vm and it's telling me

$ mustache -v
Mustache v0.99.4

Maybe updating the ruby-mustache package solves the problem? I don't know how to go about this.

@k-bx
Copy link

k-bx commented Sep 16, 2014

@locks anyway, if someone is having similar issues, I wouldn't bother and just use something else (it's all mustache!), for example there's python-pystache package for python wrapper around mustache. I've used that one when I had a problem.

@k-bx
Copy link

k-bx commented Sep 16, 2014

@locks (but just if you're very curious -- yes, I can confirm that on my non-vm ubuntu I have same output for mustache -v command)

@k-bx
Copy link

k-bx commented Sep 16, 2014

➜  tmp  mustache ./tpl.yaml ./tpl.mustache
/usr/bin/mustache:76:in `process_files': undefined method `each_document' for Psych:Module (NoMethodError)
        from /usr/bin/mustache:93:in `<main>'
➜  tmp  mustache -v                       
Mustache v0.99.4

@locks
Copy link
Member

locks commented Sep 16, 2014

That sounds like a good work around :] Hurray for interchangeable implementations!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants