ArgumentError:运行bundle exec rake时,US-ASCII中的无效字节序列(Argument错误)

问题描述 投票:0回答:2

有些人在功能分支中引入了一些测试,以匹配一些文件。当他使用bundle exec rake specbundle exec rspec modules/router/spec运行时,它们工作正常。但是当以bundle exec rake每个都应阻止失败,并带有:

ruby rake argument-error
2个回答
0
投票

因此,这是实际项目中此问题和解决方案的示例。https://github.com/alphagov/govuk-puppet/commit/63b36f93bf75a848e2125008aa1e880c5861cf46刚刚发布在这里,是为了使其可索引并且更容易搜索,请在google或此处。


0
投票

仅从GitHub复制粘贴。用于索引关键短语

将模板转换为US-ASCII以修复错误

我在功能分支中引入了一些测试以匹配以下内容:/etc/nginx/router_routes.conf。使用bundle exec rake specbundle exec rspec modules/router/spec运行时,它们工作正常。但是当以bundle exec rake每个都应阻止失败,并带有:

ArgumentError:
  invalid byte sequence in US-ASCII

[我最终发现,删除.with_content(//)匹配项会使错误消失。规范文件中没有任何奇怪的字符。和可以通过在相同的解释器中要求Puppet来复制它,如下所示:

rake -E 'require "puppet"' spec

该特定模板似乎是我们代码库中唯一带有确定utf-8的编码。所有其他都是us-ascii

dcarley-MBA:puppet dcarley$ find modules -type f -exec file --mime {} \+ | grep utf
modules/router/templates/routes.conf.erb:                                         text/plain; charset=utf-8

尝试将该文件转换回US-ASCII时已识别出问题字符,看起来像是空白:

dcarley-MBA:puppet dcarley$ iconv -f UTF8 -t US-ASCII modules/router/templates/routes.conf.erb 2>&1 | tail -n5
  proxy_intercept_errors off;

  # Set proxy timeout to 50 seconds as a quick fix for problems
  #
iconv: modules/router/templates/routes.conf.erb:458:3: cannot convert

(手动替换后,文件再次标识为us-ascii

dcarley-MBA:puppet dcarley$ file --mime modules/router/templates/routes.conf.erb
modules/router/templates/routes.conf.erb: text/plain; charset=us-ascii

现在测试工作了!我一小时的生命不会回来。

© www.soinside.com 2019 - 2024. All rights reserved.