View Template Encoding Issue

26 views
Skip to first unread message

Steven Garcia

unread,
Feb 20, 2024, 9:16:57 AM2/20/24
to Roda
This problem is driving me nuts. I am so lost..

My app:

require "roda"
require 'slim'
Slim::Engine.options[:encoding]= 'utf-8'

class App < Roda
  include Helpers
  require './models/bnb.rb'
  plugin :i18n, :locale => ['gl','es','en']
  plugin :render, engine: 'slim', views: 'views', layout: 'layout'

The error:

#<Encoding::InvalidByteSequenceError: /www/myapp/releases/18/views/home.slim is not valid US-ASCII>
/vendor/bundle/ruby/2.6.0/gems/tilt-2.0.11/lib/tilt/template.rb:95:in `initialize'
/vendor/bundle/ruby/2.6.0/gems/tilt-2.0.11/lib/tilt/mapping.rb:138:in `new'
/vendor/bundle/ruby/2.6.0/gems/tilt-2.0.11/lib/tilt/mapping.rb:138:in `new'
/vendor/bundle/ruby/2.6.0/gems/tilt-2.0.11/lib/tilt.rb:43:in `new'
/vendor/bundle/ruby/2.6.0/gems/roda-3.26.0/lib/roda/plugins/render.rb:584:in `block in retrieve_template'
/vendor/bundle/ruby/2.6.0/gems/roda-3.26.0/lib/roda/plugins/render.rb:486:in `cached_template'
/vendor/bundle/ruby/2.6.0/gems/roda-3.26.0/lib/roda/plugins/render.rb:559:in `retrieve_template'
/vendor/bundle/ruby/2.6.0/gems/roda-3.26.0/lib/roda/plugins/render.rb:348:in `render'
/vendor/bundle/ruby/2.6.0/gems/roda-3.26.0/lib/roda/plugins/render.rb:378:in `view'
es/18/app.rb:23:in `block (2 levels) in <class:App>'
/vendor/bundle/ruby/2.6.0/gems/roda-3.26.0/lib/roda.rb:1116:in `always'
/vendor/bundle/ruby/2.6.0/gems/roda-3.26.0/lib/roda.rb:955:in `root'
es/18/app.rb:20:in `block in <class:App>'
/vendor/bundle/ruby/2.6.0/gems/roda-3.26.0/lib/roda.rb:557:in `block in _roda_handle_main_route'
/vendor/bundle/ruby/2.6.0/gems/roda-3.26.0/lib/roda.rb:555:in `catch'
/vendor/bundle/ruby/2.6.0/gems/roda-3.26.0/lib/roda.rb:555:in `_roda_handle_main_route'
/vendor/bundle/ruby/2.6.0/gems/roda-3.26.0/lib/roda/plugins/error_handler.rb:87:in `_roda_handle_main_route'
/vendor/bundle/ruby/2.6.0/gems/roda-3.26.0/lib/roda/plugins/direct_call.rb:18:in `call'
/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/configuration.rb:227:in `call'
/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/server.rb:706:in `handle_request'
/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/server.rb:476:in `process_client'
/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/server.rb:334:in `block in run'
/vendor/bundle/ruby/2.6.0/gems/puma-3.12.6/lib/puma/thread_pool.rb:135:in `block in spawn_thread'

I've checked both home.slim, and layout.slim along with any included partials as follows:


$ file -I views/home.slim
$ file -I views/layout.slim
$ file -I views/_menu.slim

which all return: "text/plain; charset=utf-8"

The app runs just fine in development mode on my mac. But I cant deploy it because it keeps throwing this ascii error at me, even though clearly the files are encoded as utf8

Could it be an issue with the render plugin? Slim? I have no idea

Would be happy to send you a zipped archive of the app (its very small) if necessary

Jeremy Evans

unread,
Feb 20, 2024, 10:05:09 AM2/20/24
to ruby...@googlegroups.com
On Tue, Feb 20, 2024 at 6:16 AM Steven Garcia <steven...@gmail.com> wrote:
This problem is driving me nuts. I am so lost..

My app:

require "roda"
require 'slim'
Slim::Engine.options[:encoding]= 'utf-8'

class App < Roda
  include Helpers
  require './models/bnb.rb'
  plugin :i18n, :locale => ['gl','es','en']
  plugin :render, engine: 'slim', views: 'views', layout: 'layout'

The error:

#<Encoding::InvalidByteSequenceError: /www/myapp/releases/18/views/home.slim is not valid US-ASCII>
/vendor/bundle/ruby/2.6.0/gems/tilt-2.0.11/lib/tilt/template.rb:95:in `initialize'

As the backtrace indicates, the exception is raised by Tilt.  You probably need to set the default encoding in Tilt:

plugin :render, engine: 'slim', views: 'views', layout: 'layout', template_opts: {default_encoding: 'UTF-8'}
 
If you don't set the :default_encoding option, it defaults to Encoding.default_external, which varies depending on the environment (it's probably UTF-8 on your mac and US-ASCII where you are deploying).

Thanks,
Jeremy
Reply all
Reply to author
Forward
0 new messages