文章

"undefined method untaint"的解决

问题

在构建macdown的时候,执行bundle install遇到错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/lib/bundler/shared_helpers.rb:272:in `search_up': undefined method `untaint' for "/Users/james/working/macdown":String (NoMethodError)
      current  = File.expand_path(SharedHelpers.pwd).untaint
                                                    ^^^^^^^^
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/lib/bundler/shared_helpers.rb:259:in `find_file'
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/lib/bundler/shared_helpers.rb:251:in `find_gemfile'
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/lib/bundler/shared_helpers.rb:27:in `root'
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/lib/bundler.rb:234:in `root'
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/lib/bundler.rb:246:in `app_config_path'
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/lib/bundler.rb:273:in `settings'
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/lib/bundler/feature_flag.rb:21:in `block in settings_method'
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/lib/bundler/cli.rb:97:in `<class:CLI>'
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/lib/bundler/cli.rb:7:in `<module:Bundler>'
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/lib/bundler/cli.rb:6:in `<top (required)>'
	from <internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
	from <internal:/usr/local/Cellar/ruby/3.2.2_1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:96:in `require'
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/exe/bundle:23:in `block in <top (required)>'
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
	from /usr/local/lib/ruby/gems/3.2.0/gems/bundler-1.17.3/exe/bundle:22:in `<top (required)>'
	from /usr/local/opt/ruby/bin/bundle:25:in `load'
	from /usr/local/opt/ruby/bin/bundle:25:in `<main>'

错误载图

问题原因

经过排查,应该是我前一天通过升级gem升级了ruby版本,使得本地环境的包版本与Gemfile.lock文件中的包版本不致,所以造成这个错误。查看了一下,本机ruby的版本是3.2.2。

解决方案

删除掉Gemfile.lock,并重新执行bundle生成新的Gemfile.lock文件。

1
2
rm -f Gemfile.lock
bundle
本文由作者按照 CC BY 4.0 进行授权

Comments powered by Disqus.