获取"无效的多字节字符(US-ASCII)"当需要Ruby中的文件时

时间:2016-04-04 07:20:07

标签: ruby sass rubygems

这个问题已经添加,但我的情况似乎有点不同。

计算机:Windows Server 2012 Ruby:版本1.9.3 p484

我有我的主ruby文件file1.rb

module Sass::Script::Functions
  def dosome()
    # Doing some stuff
    begin
      success = require_relative 'myfile2.rb'
    rescue Exception => e
      puts "Error: #{e.message} - #{e.backtrace}!"
    end
  end
end

这是我的file2.rb

my_var = 'Hello world!'

我收到此错误:

  

C:/myproject/file2.rb:1:无效的多字节字符(US-ASCII)   [" C:/myproject/file1.rb:31:in require_relative'", "C:/myproject/file1.rb:31:in dosome'",   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/script/tree/funcall.rb:139:在   _perform'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/script/tree/node.rb:50:in 执行'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:384:在   visit_prop'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/base.rb:36:in 访问'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:158:在   {_ 1}}阻止在with_base'"中,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:115:在   block in visit'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:79:in with_base'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:158:在   with_frame'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:79:in 阻止(2级)在visit_if'"中,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:289:在   访问次数visit'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:289:in 阻止'",   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:179:在   map'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:289:in visit_if'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/base.rb:36:在   with_environment'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:288:in 阻止访问'",   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:79:在   visit'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:158:in with_frame'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:79:在   block in with_base'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:115:in 访问'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:491:在   with_base'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:158:in 映射'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:491:在   block (2 levels) in visit_directive'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:491:in with_environment'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:490:在   block in visit_directive'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:179:in 访问'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:158:在   {_ 1}}阻止在with_base'"中,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:115:在   visit_directive'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/base.rb:36:in with_base'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:158:在   在{visit_mixin'"中block in visit'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:79:in 阻止(4个级别),   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:353:在   在{visit_mixin'"中with_frame'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:79:in 阻止(3个级别),   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:179:在   在{visit_mixin'"中visit'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:353:in 阻止(2个级别),   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:84:在   map'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:353:in 屏蔽了visit_mixin'",   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:98:在   with_environment'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:353:in with_frame'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:98:在   perform_arguments'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:348:in visit_mixin'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/base.rb:36:在   block in with_mixin'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:115:in 阻止访问'",   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:79:在   with_mixin'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:336:in with_frame'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:79:在   visit'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:158:in 访问'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:315:在   block in with_base'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:115:in 映射'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:315:在   {_ 1}}阻止了with_import'",   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:115:在   with_base'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:158:in with_import'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:312:在   block (2 levels) in visit_import'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:315:in 访问'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:158:在   {_ 1}}阻止在with_base'"中,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:115:在   block in visit_import'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:88:in with_base'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:158:在   with_frame'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:88:in 阻止(2级)在visit_import'"中,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:315:在   visit_import'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/base.rb:36:in 阻止访问_import'",   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:88:在   block in visit'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:79:in with_frame'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:88:在   with_frame'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:79:in visit_import'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/base.rb:36:在   visit'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:315:in 阻止访问'",   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:79:在   map'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:315:in with_frame'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:79:在   block in with_import'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:115:in 访问'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/base.rb:52:在   with_import'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:312:in 映射'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/base.rb:52:在   visit'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:158:in 屏蔽了visit_children'",   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:179:在   block in with_base'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/stack.rb:115:in visit_children'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/base.rb:36:在   with_base'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:158:in visit_root'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/base.rb:36:在   block in visit_children'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/base.rb:52:in 访问'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:8:在   visit_children'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:167:in css_tree'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/root_node.rb:29:在   with_environment'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:166:in _ render_with_sourcemap'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/engine.rb:285:在   block in visit'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:186:in update_stylesheet'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/plugin/compiler.rb:215:在   visit'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/visitors/perform.rb:157:in 各'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/plugin/compiler.rb:209:在   visit'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/tree/root_node.rb:36:in update_stylesheets'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/exec/sass_scss.rb:350:在   render_with_sourcemap'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/engine.rb:368:in process_result'&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/exec/base.rb:52:在   render_with_sourcemap'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/plugin/compiler.rb:490:in 解析'!&#34 ;,   " C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/bin/scss:13:在   block in update_stylesheets'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/plugin/compiler.rb:209:in 负载'&#34 ;,   " C:/ myproject / scss:23:在''"]

即使update_stylesheets'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/plugin.rb:82:in 内没有文字,我也会这样做,如果我将watch_or_update'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/exec/sass_scss.rb:50:in 添加为parse'", "C:/tools/Ruby193/lib/ruby/gems/1.9.1/gems/sass-3.4.9/lib/sass/exec/base.rb:19:in <top (required)>'", "C:/myproject/scss:23:in的第一行,我也会这样做!

我做错了什么?如何成功要求/导入file2.rb

SASS

如您所见,这里涉及一些SASS。我不知道这是否相关。我执行脚本的方式实际上是调用SASS编译器,该编译器将对某些# coding: utf-8文件进行操作。在我的一个样式表中,我引用了file1.rb函数,这就是调用该函数的方式。

1 个答案:

答案 0 :(得分:-1)

这似乎是编码问题。 尝试添加:

# encoding: utf-8

在剧本的开头。

如果这样可行,您可以删除注释,并将两个env变量设置为运行:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

应该为编译器添加正确的标记。

但是,你使用的是什么版本的红宝石?由于Ruby 2.0不需要这样的东西,因为自动检测到UTF-8。