cinchrb / cinch

The IRC Bot Building Framework
http://www.rubydoc.info/gems/cinch
MIT License
1k stars 180 forks source link

code converter not found (UTF-8 to UTF-8) (Encoding::ConverterNotFoundError) #10

Closed pgericson closed 14 years ago

pgericson commented 14 years ago

Im using Cinch 1.0.1 and rails 3.0.0.rc and ruby 1.9.2-p0

and i get the following error:

!! Connecting to irc.freenode.org:6667
<< NICK TestmeBot
!! /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/cinch-1.0.1/lib/cinch/irc.rb:46:in `gets': code converter not found (UTF-8 to UTF-8) (Encoding::ConverterNotFoundError)
!!  /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/cinch-1.0.1/lib/cinch/irc.rb:46:in `block in connect'
<< USER TestmeBot 0 * :cinch
fatal: deadlock detected
    from /home/name/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/thread.rb:185:in `sleep'
    from /home/name/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/thread.rb:185:in `block in pop'
    from <internal:prelude>:10:in `synchronize'
    from /home/name/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/thread.rb:180:in `pop'
    from /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/cinch-1.0.1/lib/cinch/message_queue.rb:52:in `process!'
    from /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/cinch-1.0.1/lib/cinch/irc.rb:60:in `connect'
    from /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/cinch-1.0.1/lib/cinch/bot.rb:404:in `start'
    from (irb):1
    from /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/railties-3.0.0.rc/lib/rails/commands/console.rb:44:in `start'
    from /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/railties-3.0.0.rc/lib/rails/commands/console.rb:8:in `start'
    from /home/name/.rvm/gems/ruby-1.9.2-p0@getpcw/gems/railties-3.0.0.rc/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Im just testing it out, and I have a file called lib/bot.rb:

class Bot
  def self.bot
    bot = Cinch::Bot.new do
      configure do |c|
        c.server   = "irc.freenode.org"
        c.nick     = "TestmeBot"
        c.channels = ["#cinch"]
      end

      on :message, /^!msg (.+?) (.+)/ do |m, who, text|
        User(who).send text
      end
    end
  end
end

if I do $ rails console and do Bot.bot.start I get the message above. If I run it outside of rails with just `irb' it runs perfect. I don't know if its rails 3 or something eternal stuff with rails and cinch that makes it go boom :(

robbiemu commented 14 years ago

running your sample code from irb, I get the same error:

$ irb
001:0> require 'cinch'
true
002:0> Cinch::VERSION
"1.0.1"
003:0> class Bot
004:1>     def self.bot
005:2>         bot = Cinch::Bot.new do
006:3*               configure do |c|
007:4*                   c.server   = "irc.freenode.org"
008:4>                 c.nick     = "TestmeBot"
009:4>                 c.channels = ["#cinch"]
010:4>               end
011:3>       
012:3*               on :message, /^!msg (.+?) (.+)/ do |m, who, text|
013:4*                   User(who).send text
014:4>               end
015:3>           end
016:2>       end
017:1>   end
nil
018:0> Bot.bot.start
!! Connecting to irc.freenode.org:6667
<< NICK TestmeBot
!! /usr/lib/ruby/gems/1.9.3dev/gems/cinch-1.0.1/lib/cinch/irc.rb:46:in `gets': code converter not found (UTF-8 to UTF-8) (Encoding::ConverterNotFoundError)
!!  /usr/lib/ruby/gems/1.9.3dev/gems/cinch-1.0.1/lib/cinch/irc.rb:46:in `block in connect'
<< USER TestmeBot 0 * :cinch
fatal: deadlock detected
    from /usr/lib/ruby/1.9.3dev/thread.rb:189:in `sleep'
    from /usr/lib/ruby/1.9.3dev/thread.rb:189:in `block in pop'
    from :10:in `synchronize'
    from /usr/lib/ruby/1.9.3dev/thread.rb:184:in `pop'
    from /usr/lib/ruby/gems/1.9.3dev/gems/cinch-1.0.1/lib/cinch/message_queue.rb:52:in `process!'
    from /usr/lib/ruby/gems/1.9.3dev/gems/cinch-1.0.1/lib/cinch/irc.rb:60:in `connect'
    from /usr/lib/ruby/gems/1.9.3dev/gems/cinch-1.0.1/lib/cinch/bot.rb:404:in `start'
    from (irb):18
    from /usr/bin/irb:12:in `
'

my encoding stuff should be correct. my shell LANG is es_EC.utf8 and ruby picks it up as utf-8 encoding. Here is the encoding stuff from my .irbrc

# encoding: utf-8
[...]
Encoding.default_internal="utf-8"
Encoding.default_external="utf-8"
dominikh commented 14 years ago

Setting default_internal to the same value as default_external will lead to Ruby attempting to convert from utf-8 to utf-8, which is not possible.

I might include a check/fix for that, but I am unsure yet.

dominikh commented 14 years ago

check if internal and external encoding are the same

If setting both internal_encoding and external_encoding to the same encoding, Ruby will raise an exception because it can't convert between the two. But apparantly, some users have such a setup, so we explicitly check for that and don't set an internal encoding for the socket if it'd equal the external encoding.

Closed by 06891c6003e10d8cf2afdb8885a6212273039b3e