whiteleaf7 / narou

Narou.rb - 小説家になろうのダウンローダ&縦書き整形&管理アプリ。Kindle(などの電子書籍端末)でなろうを読む場合に超便利です!
Other
483 stars 56 forks source link

psych-4.0.0 に update すると narou がエラーで止まる #384

Closed saosamu closed 3 years ago

saosamu commented 3 years ago

既出かも知れませんが,とりあえず Issues 検索「psych」で引っかからなかったので報告しておきます。

gem update psych をすると narou がエラー停止します。 psych 4.0.0 を 3.0.0 に戻すとエラーが出なくなります。

ご参考まで。

詳細

gem update -systemgem update をかけたら narou がエラーで動かなくなりました。 Ruby 2.7.3 から Ruby 3.0.1 に更新し,gem udpate -system までは稼働,gem update を掛けるとエラー停止。

吐かれたエラー

C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/class_loader.rb:99:in `find': Tried to load unspecified class: Time (Psych::DisallowedClass)
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/class_loader.rb:28:in `load'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/scalar_scanner.rb:110:in `parse_time'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/scalar_scanner.rb:53:in `tokenize'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:65:in `deserialize'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:128:in `visit_Psych_Nodes_Scalar'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/visitor.rb:30:in `visit'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/visitor.rb:6:in `accept'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:35:in `accept'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:345:in `block in revive_hash'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:343:in `each'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:343:in `each_slice'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:343:in `revive_hash'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:167:in `visit_Psych_Nodes_Mapping'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/visitor.rb:30:in `visit'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/visitor.rb:6:in `accept'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:35:in `accept'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:345:in `block in revive_hash'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:343:in `each'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:343:in `each_slice'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:343:in `revive_hash'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:167:in `visit_Psych_Nodes_Mapping'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/visitor.rb:30:in `visit'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/visitor.rb:6:in `accept'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:35:in `accept'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:318:in `visit_Psych_Nodes_Document'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/visitor.rb:30:in `visit'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/visitor.rb:6:in `accept'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych/visitors/to_ruby.rb:35:in `accept'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych.rb:334:in `safe_load'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/psych-4.0.0/lib/psych.rb:369:in `load'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/inventory.rb:47:in `block in init'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/helper.rb:497:in `block in memo'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/helper.rb:490:in `synchronize'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/helper.rb:490:in `memo'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/inventory.rb:45:in `init'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/inventory.rb:23:in `block in load'
        from <internal:kernel>:90:in `tap'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/inventory.rb:21:in `load'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/database.rb:29:in `refresh'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/database.rb:25:in `initialize'
        from C:/Ruby30-x64/lib/ruby/3.0.0/singleton.rb:127:in `new'
        from C:/Ruby30-x64/lib/ruby/3.0.0/singleton.rb:127:in `block in instance'
        from C:/Ruby30-x64/lib/ruby/3.0.0/singleton.rb:125:in `synchronize'
        from C:/Ruby30-x64/lib/ruby/3.0.0/singleton.rb:125:in `instance'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/downloader.rb:247:in `<class:Downloader>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/downloader.rb:23:in `<top (required)>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/command/backup.rb:8:in `require_relative'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/command/backup.rb:8:in `<top (required)>'
        from <internal:C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from <internal:C:/Ruby30-x64/lib/ruby/site_ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:85:in `require'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/command.rb:9:in `block in <top (required)>'
        from <internal:dir>:134:in `glob'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/command.rb:8:in `<top (required)>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/commandline.rb:8:in `require_relative'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/lib/commandline.rb:8:in `<top (required)>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/narou.rb:47:in `require_relative'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/narou.rb:47:in `<top (required)>'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/bin/narou:13:in `require_relative'
        from C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/narou-3.7.1/bin/narou:13:in `<top (required)>'
        from C:/Ruby30-x64/bin/narou:23:in `load'
        from C:/Ruby30-x64/bin/narou:23:in `<main>'

psych-4.0.0 を uninstal するとエラーが出なくなります。

del "C:\Ruby30-x64\lib\ruby\gems\3.0.0\extensions\x64-mingw32\3.0.0\psych-4.0.0\psych.so"
del "C:\Ruby30-x64\lib\ruby\gems\3.0.0\gems\psych-4.0.0\lib\psych.so"
gem uninstall psych -v '4.0.0'

psych-4.0.0 を uninstall した状態で,バージョンは以下のとおりです。

$ ruby -v
ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x64-mingw32]
$ gem -v
3.2.17
$ narou -v
3.7.1
saosamu commented 3 years ago

補足。 どうも x64-mingw32 に絡むトラブルっぽいですので,恐らく narou.rb 側での問題ではないです。 もう少し調べてみます。

topstone commented 3 years ago

ここに書くほどのことでもないですが、以下の内容の Gemfile を用意して bundle exec narou ******* でも動きますね。

私の環境では psych 4.0.0 を消す代わりにこの方法で対処しました。 (psych の問題が解決した後は、Gemfile を削除する方が良いです。)

gem 'narou'
gem 'psych', '~> 3.0'
dearblue commented 3 years ago

psych 4 では Psych.loadPsych.safe_load 相当に変更されたようです。 https://github.com/ruby/psych/pull/487

もし psych 4.0.0 に対応させるとしたら、次の2つが考えられます:

whiteleaf7 commented 3 years ago
 ag "YAML.load" -l | xargs sed -i '' -e "s/YAML.load/YAML.unsafe_load/g"
whiteleaf7 commented 3 years ago

@saosamu @topstone @dearblue ありがとうございます! #387 で修正しました 後ほどバージョン更新しておきます