simplecov icon indicating copy to clipboard operation
simplecov copied to clipboard

Encoding error: Encoding::CompatibilityError, Encoding::UndefinedConversionError

Open scauglog opened this issue 10 years ago • 5 comments

with ruby 2.2.1 and simplecov 0.9.2 When i run my test with all gem included in 'vendor/cache' (I use bundle package), I have some encoding error. See full trace bellow. The issue is related to filters because when I delete all my simplecov filters everything goes right. I use continuous integration with jenkins and this error make deployment stop.

I tried to convert the string in UTF-8 but it doesn't work. Finally I manage to bypass my problem by catching this exception (I modified lib/simplecov/default.rb:7) but I don't know how to write a test for it, or how to solve the encoding problem.

/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov/defaults.rb:7:in `block (2 levels) in <top (required)>': incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string) (Encoding::CompatibilityError)
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov/filter.rb:41:in `call'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov/filter.rb:41:in `matches?'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov.rb:71:in `block (2 levels) in filtered'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov.rb:71:in `reject'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov.rb:71:in `block in filtered'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov.rb:70:in `each'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov.rb:70:in `filtered'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov/result.rb:78:in `filter!'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov/result.rb:31:in `initialize'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov.rb:44:in `new'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov.rb:44:in `result'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov/configuration.rb:158:in `block in at_exit'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov/defaults.rb:54:in `call'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/simplecov-0.9.2/lib/simplecov/defaults.rb:54:in `block in <top (required)>'
Build step 'Exécuter un script shell' marked build as failure
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Finished: FAILURE


/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/encoder.rb
/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace
/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/encoders/_map.rb
/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace
/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/encoders/terminal.rb
/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace
/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/helpers/plugin.rb
/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace
/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/json-1.8.2/lib/json/common.rb:285:in `encode': "\xC3" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/json-1.8.2/lib/json/common.rb:285:in `generate'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/json-1.8.2/lib/json/common.rb:285:in `pretty_generate'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/vendor/cache/simplecov-678462da5dd6/lib/simplecov/result_merger.rb:81:in `block (2 levels) in store_result'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/vendor/cache/simplecov-678462da5dd6/lib/simplecov/result_merger.rb:80:in `open'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/vendor/cache/simplecov-678462da5dd6/lib/simplecov/result_merger.rb:80:in `block in store_result'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/vendor/cache/simplecov-678462da5dd6/lib/simplecov/result_merger.rb:75:in `open'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/vendor/cache/simplecov-678462da5dd6/lib/simplecov/result_merger.rb:75:in `store_result'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/vendor/cache/simplecov-678462da5dd6/lib/simplecov.rb:60:in `result'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/vendor/cache/simplecov-678462da5dd6/lib/simplecov/configuration.rb:159:in `block in at_exit'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/vendor/cache/simplecov-678462da5dd6/lib/simplecov/defaults.rb:66:in `call'
    from /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/vendor/cache/simplecov-678462da5dd6/lib/simplecov/defaults.rb:66:in `block in <top (required)>'
Build step 'Exécuter un script shell' marked build as failure
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Finished: FAILURE

scauglog avatar May 16 '15 14:05 scauglog

Do you know what the incompatible Encoding::CompatibilityError (UTF-8 regexp with ASCII-8BIT string) string is so we can test against it?

above your lib/simplecov/default.rb:7 patch (what did you change !(src.filename =~ /^#{Regexp.escape(SimpleCov.root)}/i) to, can you add

p [Encoding.default_external, Encoding.default_internal, Encoding.find('locale'), Encoding.find('filesystem'), __ENCODING__, src.filename.encoding, src.filename.valid_encoding?, SimpleCov.root.to_s.encoding, SimpleCov.root.to_s.valid_encoding?, Encoding.compatibile?(src.filename, SimpleCov.root), Encoding.compatibile?(src.filename.force_encoding(Encoding::BINARY), SimpleCov.root.to_s.force_encoding(Encoding::BINARY))]`

(it's possible there's typos in that.. I just wrote it up

bf4 avatar May 17 '15 13:05 bf4

@colszowka can you add a 'waiting for response' label?

bf4 avatar May 17 '15 20:05 bf4

force_encoding return an error :

force_encoding': can't modify frozen String (RuntimeError)

the wrong string are filename:

/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/encoder.rb
/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/encoders/_map.rb
/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/encoders/terminal.rb
/var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/helpers/plugin.rb

output of the rescue with ( p [Encoding.default_external, Encoding.default_internal, Encoding.find('locale'), Encoding.find('filesystem'), __ENCODING__, src.filename.encoding, src.filename.valid_encoding?, SimpleCov.root.to_s.encoding, SimpleCov.root.to_s.valid_encoding?, Encoding.compatible?(src.filename, SimpleCov.root)] )

[#<Encoding:UTF-8>, nil, #<Encoding:UTF-8>, #<Encoding:UTF-8>, #<Encoding:UTF-8>, #<Encoding:ASCII-8BIT>, true, #<Encoding:UTF-8>, true, nil]
Warning: Encoding::CompatibilityError
skip file : /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/encoder.rb

[#<Encoding:UTF-8>, nil, #<Encoding:UTF-8>, #<Encoding:UTF-8>, #<Encoding:UTF-8>, #<Encoding:ASCII-8BIT>, true, #<Encoding:UTF-8>, true, nil]
Warning: Encoding::CompatibilityError
skip file : /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/encoders/_map.rb

[#<Encoding:UTF-8>, nil, #<Encoding:UTF-8>, #<Encoding:UTF-8>, #<Encoding:UTF-8>, #<Encoding:ASCII-8BIT>, true, #<Encoding:UTF-8>, true, nil]
Warning: Encoding::CompatibilityError
skip file : /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/encoders/terminal.rb

[#<Encoding:UTF-8>, nil, #<Encoding:UTF-8>, #<Encoding:UTF-8>, #<Encoding:UTF-8>, #<Encoding:ASCII-8BIT>, true, #<Encoding:UTF-8>, true, nil]
Warning: Encoding::CompatibilityError
skip file : /var/lib/jenkins/jobs/data-retriever_01_Préparation/workspace/bundle/ruby/2.2.0/gems/coderay-1.1.0/lib/coderay/helpers/plugin.rb

scauglog avatar May 18 '15 16:05 scauglog

Oh, SimpleCov.root.to_s.dup.force_encoding(Encoding::BINARY)) missing the .dup

bf4 avatar Jun 12 '15 00:06 bf4

Another encoding bug related thingy :(

PragTob avatar Dec 03 '19 16:12 PragTob