Techioz Blog

Windows 上の特定のディレクトリのバンドラー コマンドに関するエラー: Ruby 3.3.0 の「untaint」メソッドの NoMethodError

概要

GitHub ページに記載されている手順に従って ltx2any をインストールしようとしたときに問題が発生しました。私は Ruby にあまり詳しくないので、Windows 上の Chocolatey を使用してインストールしました。次に、gem install Bundler コマンドを使用して Bundler をインストールしました。

クローンされた ltx2any ディレクトリ以外のディレクトリで Bundler -v を実行すると、Bundler バージョン 2.5.5 を示す正しい出力が得られます。ただし、クローン作成された ltx2any ディレクトリで Bundler コマンドを実行しようとすると、次のエラー メッセージが表示されます。

C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/shared_helpers.rb:266:in `search_up': undefined method `untaint' for an instance of String (NoMethodError)

      current  = File.expand_path(SharedHelpers.pwd).untaint
                                                    ^^^^^^^^
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/shared_helpers.rb:253:in `find_file'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/shared_helpers.rb:245:in `find_gemfile'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/shared_helpers.rb:27:in `root'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler.rb:218:in `root'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler.rb:230:in `app_config_path'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler.rb:257:in `settings'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/env.rb:20:in `report'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/friendly_errors.rb:96:in `request_issue_report_for'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/friendly_errors.rb:46:in `log_error'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/friendly_errors.rb:126:in `rescue in with_friendly_errors'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/exe/bundle:22:in `<top (required)>'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/exe/bundler:4:in `load'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/exe/bundler:4:in `<top (required)>'
        from C:/tools/ruby33/bin/bundler:32:in `load'
        from C:/tools/ruby33/bin/bundler:32:in `<main>'
C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/shared_helpers.rb:266:in `search_up': undefined method `untaint' for an instance of String (NoMethodError)

      current  = File.expand_path(SharedHelpers.pwd).untaint
                                                    ^^^^^^^^
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/shared_helpers.rb:253:in `find_file'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/shared_helpers.rb:245:in `find_gemfile'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/shared_helpers.rb:27:in `root'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler.rb:218:in `root'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler.rb:230:in `app_config_path'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler.rb:257:in `settings'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/feature_flag.rb:21:in `block in settings_method'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/cli.rb:97:in `<class:CLI>'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/cli.rb:7:in `<module:Bundler>'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/cli.rb:6:in `<top (required)>'
        from <internal:C:/tools/ruby33/lib/ruby/site_ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
        from <internal:C:/tools/ruby33/lib/ruby/site_ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/exe/bundle:23:in `block in <top (required)>'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/lib/bundler/friendly_errors.rb:122:in `with_friendly_errors'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/exe/bundle:22:in `<top (required)>'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/exe/bundler:4:in `load'
        from C:/Users/FooBar/.local/share/gem/ruby/3.3.0/gems/bundler-1.16.1/exe/bundler:4:in `<top (required)>'
        from C:/tools/ruby33/bin/bundler:32:in `load'
        from C:/tools/ruby33/bin/bundler:32:in `<main>'

このエラーは untaint メソッドに関連しているようですが、このメソッドは Ruby 3.2 以降では削除されたと私は理解しています。ただし、Bundler 2.5.5 がインストールされているにもかかわらず、ltx2any ディレクトリで Bundler 1.16.1 を使用しようとする理由はわかりません。

これまでに試したことは次のとおりです。

この問題を解決する方法についての洞察や提案をいただければ幸いです。具体的には、次のことを理解したいと考えています。

追伸フォローアップの質問をここに投稿しました。

解決策

新しいバージョンのバンドラーでは、Gemfile.lock の作成に使用されたバンドラーのバージョンが記憶されます。その後、この Gemfile.lock を使用した今後のすべての呼び出しに、この正確なバージョンがインストールされて使用されます。

この機能の詳細については、この機能に関する発表ブログ投稿「Bundler v2.3: Locking the version of Bundler self」を参照してください。

Gemfile.lock で最新の Bundler バージョンを使用するには、それに応じて Bundle update –bundler を実行する必要があるでしょう。その後、bundle install を再度実行して、更新された Bundler バージョンを使用して Gemfile / Gemfile.lock から gem をインストールできます。