floraison / et-orbi

Time zones for fugit and rufus-scheduler. Urbi et Orbi.
MIT License
24 stars 11 forks source link

'sub': invalid byte sequence in UTF-8 (ArgumentError) #15

Closed MTRNord closed 6 years ago

MTRNord commented 6 years ago

Related to https://github.com/jmettraux/rufus-scheduler/issues/277

I use rufus-scheduler and I am not sure where to report it but most of the stacktrace mentions this lib:

C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi/zone_aliases.rb:6:in `sub': invalid byte sequence in UTF-8 (ArgumentError)
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi/zone_aliases.rb:6:in `unalias'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:156:in `get_tzone'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:699:in `determine_local_tzone'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:148:in `get_tzone'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:269:in `get_tzone'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:307:in `initialize'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:21:in `new'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:21:in `now'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:259:in `now'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rufus-scheduler-3.5.2/lib/rufus/scheduler.rb:539:in `start'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/rufus-scheduler-3.5.2/lib/rufus/scheduler.rb:88:in `initialize'
        from C:/Users/marce/RubymineProjects/node_alert/main.rb:114:in `new'
        from C:/Users/marce/RubymineProjects/node_alert/main.rb:114:in `<main>'

I am using windows 10. tzinfo is loaded inside the Gemfile.

Simplified code I used to cause this is:

scheduler = Rufus::Scheduler.new
scheduler.every '10m' do
  puts '10'
end
jmettraux commented 6 years ago

Hello @MTRNord,

thanks for reporting this problem.

What does

ruby -r et-orbi -e "EtOrbi._make_info"

yield on your system?

MTRNord commented 6 years ago

@jmettraux

Looks like the same error.

C:\Users\marce\RubymineProjects\knotenmailer>C:\Ruby24-x64\bin\ruby -r et-orbi -e "EtOrbi._make_info"
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi/zone_aliases.rb:6:in `sub': invalid byte sequence in UTF-8 (ArgumentError)
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi/zone_aliases.rb:6:in `unalias'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:156:in `get_tzone'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:699:in `determine_local_tzone'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:170:in `render_nozone_time'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:209:in `_make_info'
        from -e:1:in `<main>'
jmettraux commented 6 years ago

Hello @MTRNord,

thanks a lot. I'll have a closer look when I'm back home tomorrow.

Best regards.

jmettraux commented 6 years ago

Hello,

what does this program yield on your system?


require 'et-orbi'

module EtOrbi

  def self.unalias(name)

p [ name, name.encoding ]
    ZONE_ALIASES[name.sub(/ Daylight /, ' Standard ')] ||
    unzz(name) ||
    name
  end
end

puts
puts '0 ---'
p EtOrbi::EoTime.now

puts
puts '1 ---'
EtOrbi._make_info
puts
MTRNord commented 6 years ago

It returns this:

C:\Ruby24-x64\bin\ruby.exe C:/Users/marce/RubymineProjects/node_alert/test.rb

0 ---
["Mitteleurop\xE4ische Sommerzeit", #<Encoding:UTF-8>]
C:/Users/marce/RubymineProjects/node_alert/test.rb:9:in `sub': invalid byte sequence in UTF-8 (ArgumentError)
        from C:/Users/marce/RubymineProjects/node_alert/test.rb:9:in `unalias'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:156:in `get_tzone'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:699:in `determine_local_tzone'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:148:in `get_tzone'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:269:in `get_tzone'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:307:in `initialize'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:21:in `new'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:21:in `now'
        from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/et-orbi-1.1.4/lib/et-orbi.rb:259:in `now'
        from C:/Users/marce/RubymineProjects/node_alert/test.rb:18:in `<main>'

Process finished with exit code 1
MTRNord commented 6 years ago

Oh I guess it is because it gets returned in german and german has a ä character in the text

jmettraux commented 6 years ago

Thank you very much! I will fix that now.

MTRNord commented 6 years ago

PS: not sure if you need the info but the returned string seems to be returned in iso-8859-1 and wrongly interpreted as UTF-8.

Using following converting fixes this error already (but after that it is unable to detect the timezone)

name = name.force_encoding('iso-8859-1')
name = name.encode('utf-8')

See: https://stackoverflow.com/a/31644169/4929236

jmettraux commented 6 years ago

Using following converting fixes this error already (but after that it is unable to detect the timezone)

Thanks. Yes, Windows is difficult to support :-(

MTRNord commented 6 years ago

Yeah windows is always "fun" (fun as in->more work) :/ but thanks anyway for taking the time

jmettraux commented 6 years ago

Hello again,

is the commit above helping with the issue?

If auto-detection fails, you can insert

ENV['TZ'] = 'Europe/Berlin'

on top of your Ruby script to force it somehow.

If it still doesn't work, please give me the (newer) output of ruby -r et-orbi -e "EtOrbi._make_info"

MTRNord commented 6 years ago

@jmettraux yes that works :) only autodetection obviously does not but I guess translating everything to make it work would be more work than adding a real benefit

jmettraux commented 6 years ago

Thanks a lot, I will refine this fix and release 1.1.5 soon.

jmettraux commented 6 years ago

et-orbi 1.1.5 released: https://rubygems.org/gems/et-orbi

Thanks again.