8

Why do I get this error ?

invalid byte sequence in UTF-8

for loading an image in:

= image_tag 'features_home/show1.png'

EDIT

I've notice that this issue occurred only after I did bundle update, the error occurs with any image.. I will try to add details here:

Stacktrace:

  Rendered home/home.html.haml within layouts/application (229.9ms)
Completed 500 Internal Server Error in 1047ms
invalid byte sequence in UTF-8 excluded from capture: DSN not set

ActionView::Template::Error (invalid byte sequence in UTF-8):
    81:           / Carousel items
    82:           .carousel-inner
    83:             .active.item
    84:               = image_tag 'features_home/show1.png'
    85:               -#.carousel-caption
    86:               -#  %h4
    87:               -#  %p
  app/views/home/home.html.haml:84:in `block in _app_views_home_home_html_haml__623651309533727079_70331260863620'
  app/views/home/home.html.haml:33:in `_app_views_home_home_html_haml__623651309533727079_70331260863620'
  lib/rack/seoredirect.rb:20:in `call'


  Rendered /Users/Apple/.rvm/gems/ruby-2.2.2@myapp/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (115.6ms)
  Rendered /Users/Apple/.rvm/gems/ruby-2.2.2@myapp/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (23.1ms)
  Rendered /Users/Apple/.rvm/gems/ruby-2.2.2@myapp/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.7ms)
  Rendered /Users/Apple/.rvm/gems/ruby-2.2.2@myapp/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (237.9ms)

Gemfile.lock before and after bundle update: https://gist.github.com/hopewise/35c2a98b13ac646b65770feb2f3c7ec8

Full trace: https://gist.github.com/hopewise/551169518a5938647dc767d3de393cd4

I don't know which gem caused the issue though..

simo
  • 23,342
  • 38
  • 121
  • 218

1 Answers1

0

This appears to be a bug in the less-rails gem that Haml uses to resolve paths for the image_tag directive.

When invoking image_tag, less-rails eventually attempts to scan for assets that the file depends on but may inadvertently consume non-text files. This results in the error you experience.

A fix exists on a (somewhat outdated) branch in the project that verifies the path correctly. We can pull in for testing:

gem 'less-rails', github: 'metaskills/less-rails', branch: 'depends_only_on_less_files' 

Please see this ticket for more detailed information. As suggested there, you may need to verify that the code uses an appropriate path for the image.

Cy Rossignol
  • 16,216
  • 4
  • 57
  • 83