jugyo / termtter

moved to https://github.com/termtter/termtter
201 stars 34 forks source link

w3mimg plugin等でiconの処理で例外が出ることがある #107

Closed ohac closed 14 years ago

ohac commented 14 years ago

とりあえずメモ:

./lib/plugins/w3mimg.rb:28:in `from_blob': Negative or zero image size `' @ gif.c/ReadGIFImage/1237 (Magick::ImageMagickError)
from ./lib/plugins/w3mimg.rb:28:in `get_icon_path'
from ./lib/plugins/w3mimg.rb:17:in `open'
from ./lib/plugins/w3mimg.rb:17:in `get_icon_path'
from ./lib/plugins/w3mimg.rb:58
from ./lib/plugins/w3mimg.rb:56:in `map'
from ./lib/plugins/w3mimg.rb:56
from ./lib/plugins/w3mimg.rb:55:in `start'
from ./lib/plugins/w3mimg.rb:55
from ./lib/termtter/hook.rb:28:in `call'
from ./lib/termtter/hook.rb:28:in `call'
from ./lib/termtter/client.rb:121:in `output'
from ./lib/termtter/client.rb:120:in `each'
from ./lib/termtter/client.rb:120:in `output'
from ./lib/plugins/defaults/standard_commands.rb:22
from ./lib/termtter/command.rb:62:in `call'
from ./lib/termtter/command.rb:62:in `call'
from ./lib/termtter/client.rb:165:in `call_commands'
from ./lib/termtter/client.rb:153:in `each'
from ./lib/termtter/client.rb:153:in `call_commands'
from ./lib/termtter/task_manager.rb:49:in `invoke_and_wait'
from ./lib/termtter/task_manager.rb:81:in `synchronize'
from ./lib/termtter/task_manager.rb:48:in `invoke_and_wait'
from ./lib/termtter/client.rb:142:in `call_commands'
from ./lib/plugins/another_prompt.rb:50
from ./lib/termtter/task.rb:15:in `call'
from ./lib/termtter/task.rb:15:in `execute'
from ./lib/termtter/task_manager.rb:36:in `step'
from ./lib/termtter/task_manager.rb:49:in `invoke_and_wait'
from ./lib/termtter/task_manager.rb:81:in `synchronize'
from ./lib/termtter/task_manager.rb:48:in `invoke_and_wait'
from ./lib/termtter/task_manager.rb:35:in `step'
from ./lib/termtter/task_manager.rb:34:in `each'
from ./lib/termtter/task_manager.rb:34:in `step'
from ./lib/termtter/task_manager.rb:27:in `run'
from ./lib/termtter/task_manager.rb:25:in `initialize'
from ./lib/termtter/task_manager.rb:25:in `new'
from ./lib/termtter/task_manager.rb:25:in `run'
from ./lib/termtter/client.rb:300:in `run'
from ./run_termtter.rb:21
ohac commented 14 years ago
diff --git a/lib/plugins/w3mimg.rb b/lib/plugins/w3mimg.rb
index 10868a6..ee4d23c 100644
--- a/lib/plugins/w3mimg.rb
+++ b/lib/plugins/w3mimg.rb
@@ -28,6 +28,8 @@ def get_icon_path(s)
         rimage = Magick::Image.from_blob(image).first
         rimage = rimage.resize_to_fill(48, 48)
         f << rimage.to_blob
+      rescue Magick::ImageMagickError
+        return nil
       rescue Net::ProtocolError
         return nil
       end

こんな感じかな?

ohac commented 14 years ago

そのときの ~/.termtter/tmp/user_profile_images/prototechno.png は 0 バイトでした。 サンタアイコンを元に戻したときにエラーが出るようになった。 このファイルを消して再起動してみましたが、また0バイトのファイルができた。 wgetではgetできる。

ohac commented 14 years ago

再現用のコード。どうやらアニメpngをRMagickがうまく処理できてないっぽい。

require 'RMagick'
require 'uri'
require 'net/http'
url = 'http://a1.twimg.com/profile_images/591916558/3tomoe_normal_bigger_normal.png'
http_class = Net::HTTP
uri = URI.parse(URI.escape(url))
image = http_class.get(uri.host, uri.path, uri.port)
p image.size
Magick::Image.from_blob(image)
ohac commented 14 years ago

b4704c0ea6e910f17c976fc0d282a0c09491df4e