jugyo / earthquake

Twitter terminal client with streaming API support.
MIT License
661 stars 94 forks source link

Uncaught Exception converting t.co links #125

Open seppo0010 opened 12 years ago

seppo0010 commented 12 years ago

No idea when this happens.

/Users/seppo/.earthquake/plugin/expand_tco.rb:11:in gsub!': can't convert nil into String (TypeError) from /Users/seppo/.earthquake/plugin/expand_tco.rb:11:inblock (5 levels) in <top (required)>' from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:1322:in block (2 levels) in transport_request' from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:2671:inreading_body' from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:1321:in block in transport_request' from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:1316:incatch' from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:1316:in transport_request' from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:1293:inrequest' from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:1195:in request_get' from /Users/seppo/.earthquake/plugin/expand_tco.rb:10:inblock (4 levels) in <top (required)>' from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:745:in start' from /opt/local/lib/ruby1.9/1.9.1/net/http.rb:557:instart' from /Users/seppo/.earthquake/plugin/expand_tco.rb:9:in block (3 levels) in <top (required)>' from /Users/seppo/.earthquake/plugin/expand_tco.rb:7:ineach' from /Users/seppo/.earthquake/plugin/expand_tco.rb:7:in block (2 levels) in <top (required)>' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/output.rb:36:incall' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/output.rb:36:in block (2 levels) in puts_items' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/output.rb:36:ineach' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/output.rb:36:in any?' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/output.rb:36:inblock in puts_items' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/output.rb:35:in reverse_each' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/output.rb:35:inputs_items' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/output.rb:26:in block in output' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/output.rb:56:ininsert' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/output.rb:23:in output' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/core.rb:127:inblock (4 levels) in start' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/core.rb:209:in call' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/core.rb:209:inblock in sync' from internal:prelude:10:in synchronize' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/core.rb:208:insync' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/core.rb:127:in block (3 levels) in start' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/core.rb:125:inloop' from /opt/local/lib/ruby1.9/gems/1.9.1/gems/earthquake-0.9.0/lib/earthquake/core.rb:125:in `block (2 levels) in start'

no6v commented 12 years ago

Would you show us your version of earthquake.gem and /Users/seppo/.earthquake/plugin/expand_tco.rb ? This is a problem on custom plugin, I guess.

FYI: shortened urls will be expanded if the tweet includes "entities" when the config[:expand_url] is true since version 0.8.4.

seppo0010 commented 12 years ago

Earthquake v0.9.0

expand_tco.rb:

require 'net/http'
require 'uri'
Earthquake.init do
    output_filter do |item|
        next unless item['text']
        text = item["text"]
        text.scan( /http:\/\/t\.co\/[a-zA-Z0-9\-]+/ ).each do |url|
            uri = URI.parse url
            Net::HTTP::start( uri.host , uri.port ) do |connection|
                connection.request_get uri.path do |response|
                    text.gsub! url , response['Location']
                end
            end
        end
        text
    end
end
# https://gist.github.com/1385833
seppo0010 commented 12 years ago

Oh, it seems like this crash was discussed in the gist https://gist.github.com/1385833

jaspertandy commented:

Ah, I actually came across a similar issue using this previously. The problem actually stems from the core code of earthquake, in that the tweet body of a retweet is stored in a different variable to a regular tweet, which is quite annoying! I ended up (probably foolishly) making a modification to the core of earthquake to fix the issue for myself, but the modification I've made to the existing gist should skirt the issue (though you may still see t.co in retweets).