blinry / nom

"Lose weight and hair through stress and poor nutrition"
GNU General Public License v2.0
64 stars 4 forks source link

Fix breaking problem on Ruby upgrade #13

Closed rixx closed 1 year ago

rixx commented 1 year ago

I updated my Ruby install today, and nom didn't run afterwards:

/usr/lib/ruby/3.0.0/psych/class_loader.rb:99:in `find': Tried to load unspecified class: Date (Psych::DisallowedClass)
    from /usr/lib/ruby/3.0.0/psych/class_loader.rb:28:in `load'
    from (eval):2:in `date'
    from /usr/lib/ruby/3.0.0/psych/scalar_scanner.rb:66:in `tokenize'
    from /usr/lib/ruby/3.0.0/psych/visitors/to_ruby.rb:65:in `deserialize'
    from /usr/lib/ruby/3.0.0/psych/visitors/to_ruby.rb:130:in `visit_Psych_Nodes_Scalar'
    from /usr/lib/ruby/3.0.0/psych/visitors/visitor.rb:30:in `visit'
    from /usr/lib/ruby/3.0.0/psych/visitors/visitor.rb:6:in `accept'
    from /usr/lib/ruby/3.0.0/psych/visitors/to_ruby.rb:35:in `accept'
    from /usr/lib/ruby/3.0.0/psych/visitors/to_ruby.rb:347:in `block in revive_hash'
    from /usr/lib/ruby/3.0.0/psych/visitors/to_ruby.rb:345:in `each'
    from /usr/lib/ruby/3.0.0/psych/visitors/to_ruby.rb:345:in `each_slice'
    from /usr/lib/ruby/3.0.0/psych/visitors/to_ruby.rb:345:in `revive_hash'
    from /usr/lib/ruby/3.0.0/psych/visitors/to_ruby.rb:169:in `visit_Psych_Nodes_Mapping'
    from /usr/lib/ruby/3.0.0/psych/visitors/visitor.rb:30:in `visit'
    from /usr/lib/ruby/3.0.0/psych/visitors/visitor.rb:6:in `accept'
    from /usr/lib/ruby/3.0.0/psych/visitors/to_ruby.rb:35:in `accept'
    from /usr/lib/ruby/3.0.0/psych/visitors/to_ruby.rb:320:in `visit_Psych_Nodes_Document'
    from /usr/lib/ruby/3.0.0/psych/visitors/visitor.rb:30:in `visit'
    from /usr/lib/ruby/3.0.0/psych/visitors/visitor.rb:6:in `accept'
    from /usr/lib/ruby/3.0.0/psych/visitors/to_ruby.rb:35:in `accept'
    from /usr/lib/ruby/3.0.0/psych.rb:334:in `safe_load'
    from /usr/lib/ruby/3.0.0/psych.rb:369:in `load'
    from /usr/lib/ruby/3.0.0/psych.rb:671:in `block in load_file'
    from /usr/lib/ruby/3.0.0/psych.rb:670:in `open'
    from /usr/lib/ruby/3.0.0/psych.rb:670:in `load_file'
    from /home/rixx/.local/share/gem/ruby/3.0.0/gems/nom-0.1.4/lib/nom/config.rb:10:in `initialize'
    from /home/rixx/.local/share/gem/ruby/3.0.0/gems/nom-0.1.4/lib/nom/nom.rb:30:in `new'
    from /home/rixx/.local/share/gem/ruby/3.0.0/gems/nom-0.1.4/lib/nom/nom.rb:30:in `initialize'
    from /home/rixx/.local/share/gem/ruby/3.0.0/gems/nom-0.1.4/bin/nom:27:in `new'
    from /home/rixx/.local/share/gem/ruby/3.0.0/gems/nom-0.1.4/bin/nom:27:in `<top (required)>'
    from /home/rixx/.local/share/gem/ruby/3.0.0/bin/nom:25:in `load'
    from /home/rixx/.local/share/gem/ruby/3.0.0/bin/nom:25:in `<main>'

Apparently YAML loads require some classes to be whitelisted first. Fix tested by editing the installed file in-place, and everything works great again.

blinry commented 1 year ago

Perfect, thanks for the PR! :)

blinry commented 1 year ago

Released v0.1.5!

rohieb commented 1 year ago

Hmmm, I didn't upgrade my Ruby install, and now I'm getting

$ nom p
+ exec ruby -I~/projects/nom/lib -- /home/rohieb/projects/nom/bin/nom p
Traceback (most recent call last):
    5: from /home/rohieb/projects/nom/bin/nom:27:in `<main>'
    4: from /home/rohieb/projects/nom/bin/nom:27:in `new'
    3: from /home/rohieb/projects/nom/lib/nom/nom.rb:30:in `initialize'
    2: from /home/rohieb/projects/nom/lib/nom/nom.rb:30:in `new'
    1: from /home/rohieb/projects/nom/lib/nom/config.rb:10:in `initialize'
/usr/lib/ruby/2.7.0/psych.rb:576:in `load_file': unknown keyword: :permitted_classes (ArgumentError)

(the first line is my very trivial ~/bin/nom wrapper, which runs with sh -x shebang)

More info:

$ ruby --version
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux-gnu]

Does anyone know ruby well enough to find out what's wrong here?

rixx commented 1 year ago

I don't know Ruby well at all, and I'm sorry for any problems I've caused! It seems to me that 2.7.x is pretty old? Mine is on 3.0, and I think the 3.x update is what caused the problem. I suppose we'll need code to distinguish by version?