<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,8 +1,11 @@
 require &quot;rfeedparser&quot;
 require &quot;feedbag&quot;
+require &quot;terminator&quot;
 require &quot;goodies/goodies/lwr-simple&quot;
 require 'digest/md5'
 
+Hpricot.buffer_size = 262144
+
 class Feed &lt; ActiveRecord::Base
 	has_many :posts
 
@@ -29,14 +32,28 @@ class Feed &lt; ActiveRecord::Base
 	end
 	
 	def before_created
-    self.url = LWR::Simple.normalize(self.url).to_s
+	  unless self.url
+	    self.errors.add :feed_url, &quot;was not specified&quot;
+	    return false
+	  end
+	  
+	  # there's very few cases where the normalized url could be
+	  # fucked up, this is not exactly a bug on LWR
+	  begin
+      self.url = LWR::Simple.normalize(self.url).to_s
+    rescue =&gt; ex
+      $stderr.puts &quot;Unrecoverable error with `#{self.url}' on #{ex.class}:&quot;
+      $stderr.puts &quot; #{ex.message}&quot;
+      self.errors.add :feed_url, &quot;was fucked up&quot;
+      return false
+    end
 
     # checking that the url is a feed:
     feedbag = Feedbag.find(url)
     if feedbag.size == 1 and feedbag.first == url
       # si es
     elsif feedbag.first.nil?
-      $stderr.puts &quot;URL not a feed and not feeds found&quot;
+      self.errors.add :feed_url, &quot;not a feed and not feeds found&quot;
       return false
     else
       self.url = feedbag.first
@@ -44,14 +61,27 @@ class Feed &lt; ActiveRecord::Base
     end
 
     self.feed_url = self.url
-		fp = FeedParser.parse self.url
+
+    fp = nil
+    begin
+      Terminator.terminate 20 do
+        fp = FeedParser.parse self.url
+      end
+    rescue Terminator::Error =&gt; ex
+      self.errors.add :feed_url, &quot;- #{ex.class} error ocurred: #{ex.message}&quot;
+      return false
+    rescue
+      self.errors.add :feed_url, &quot;- Internal malfunction, mail developers&quot;
+      return false
+    end
 
 		if fp.status.nil? or fp.status &gt;= 400.to_s
-      $stderr.puts &quot;Errors with #{url}!&quot;
+		  self.errors.add :feed_url, &quot;couldn't be fetched or returned HTTP bad code&quot;
       return false
     end
 
 		if fp.status == &quot;304&quot; and fp.feed.empty? and fp.entries.empty? # not changed!
+		  self.errors.add :feed_url, &quot;unchanged or empty&quot;
 			return false
 		end
 
@@ -70,43 +100,55 @@ class Feed &lt; ActiveRecord::Base
         v = W3C::FeedValidator.new
         v.validate_url self.url
         unless v.valid?
-          $stderr.puts &quot;Invalid feed&quot;
+          self.errors.add :feed_url, &quot;didn't look like a feed and didn't pass the w3c validation&quot;
           return false
         end
       end
     end
     
-    self.link = fp.feed.link
+    self.link = fp.feed.link || self.feed_url
     self.title = fp.feed.title
     true # if i made it this far, it was successful callback  
 	end
 
 	def before_updated
-	  if self.etag and self.last_modified
-	    puts &quot;Both etag and last_modified&quot;
-	    self.fp = FeedParser.parse self.feed_url, { :etag =&gt; self.etag, :modified =&gt; self.last_modified }
-	  elsif self.etag
-	    puts &quot;Only etag&quot;
-	    self.fp = FeedParser.parse self.feed_url, { :etag =&gt; self.etag }
-	  elsif self.last_modified
-	    puts &quot;Only last_modified&quot;
-	    self.fp = FeedParser.parse self.feed_url, { :modified =&gt; self.last_modified }
-	  else
-	    puts &quot;Neither etag or last_modified&quot;
-	    self.fp = FeedParser.parse self.feed_url
-	  end
+    $stdout.puts &quot;=&gt; #{self.feed_url}&quot;
+    begin
+      Terminator.terminate 20 do
+        if self.etag and self.last_modified
+          puts &quot;Both etag and last_modified&quot;
+          self.fp = FeedParser.parse self.feed_url, { :etag =&gt; self.etag, :modified =&gt; self.last_modified }
+        elsif self.etag
+          puts &quot;Only etag&quot;
+          self.fp = FeedParser.parse self.feed_url, { :etag =&gt; self.etag }
+        elsif self.last_modified
+          puts &quot;Only last_modified&quot;
+          self.fp = FeedParser.parse self.feed_url, { :modified =&gt; self.last_modified }
+        else
+          puts &quot;Neither etag or last_modified&quot;
+          self.fp = FeedParser.parse self.feed_url
+        end
+      end
+    rescue Terminator::Error =&gt; ex
+      self.errors.add :feed_url, &quot;- #{ex.class} error ocurred: #{ex.message}&quot;
+      return false
+    rescue
+      self.errors.add :feed_url, &quot;- Internal malfunction&quot;
+      return false
+    end
+
 	
 		if self.fp.status.nil? or self.fp.status &gt;= 400.to_s
-      $stderr.puts &quot;Errors with #{self.feed_url}!&quot;
+		  self.errors.add :feed_url, &quot;couldn't be fetched or returned HTTP bad code&quot;
       return false
     end
 
 		if self.fp.status == &quot;304&quot; and self.fp.feed.empty? and self.fp.entries.empty? # not changed!
-		  $stderr.puts &quot;Feed unchanged (not updating)!&quot;
+		  self.errors.add :feed_url, &quot;unchanged or empty&quot;
 			return false
 		end
     
-		self.link = self.fp.feed.link
+		self.link = self.fp.feed.link || self.feed_url 
 		self.title = self.fp.feed.title unless self.title
 		self.etag = self.fp.etag
 		self.last_modified = self.fp.modified_time
@@ -132,27 +174,5 @@ class Feed &lt; ActiveRecord::Base
 		true 
 	end
 
-  # def fetch
-  #   parse(self.feed_url, :etag =&gt; self.etag, :modified =&gt; self.last_modified)
-  # 
-  #   # unless self.changed
-  #  #     puts &quot;#{self.name}: Feed unchanged&quot;
-  #  #     return
-  #  #   end
-  # 
-  #   self.fp.entries.each do |e|
-  #     post = Post.entry(e, self)
-  #   end
-  # 
-  #   self.save
-  # 
-  #   if feed.save
-  #     puts &quot;#{feed.name} successfully fetched!&quot;
-  #   else
-  #     puts feed.errors.full_messages
-  #     pp feed
-  #   end
-  # end
-
 
 end</diff>
      <filename>lib/rfeed/models/Feed.rb</filename>
    </modified>
    <modified>
      <diff>@@ -6,7 +6,7 @@ class Post &lt; ActiveRecord::Base
 		
 	def self.entry(e, feed = nil)
 		entry_id = nil
-		if not e[&quot;id&quot;].empty? # e.id will try to trigger Object.id
+		if not e[&quot;id&quot;].nil? and not e[&quot;id&quot;].empty? # e.id will try to trigger Object.id
 			puts &quot;using id&quot;
 			entry_id = e[&quot;id&quot;]
 		elsif not e.link.empty?
@@ -25,7 +25,13 @@ class Post &lt; ActiveRecord::Base
 
 		post = Post.find_or_create_by_entry_id(entry_id)
 		post.feed_id = feed[&quot;id&quot;]
-		post.link = e.link || e.links[0][&quot;href&quot;] || feed.link || &quot;#&quot;
+
+    begin
+      post.link = e.link || e.links[0][&quot;href&quot;] || feed.link
+    rescue
+      post.link = &quot;#&quot;
+    end
+    
 		post.title = e.title || e.link
 		post.description = e.description || e.content || e.summary || &quot;no content&quot;
 		post.date = e.created_time || e.updated_time || e.published_time || feed.fp.updated_time || feed.fp.modified_time || Time.now</diff>
      <filename>lib/rfeed/models/Post.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>df0f0229d1dd2d4c8e3d8a291f67f54ffa926ee3</id>
    </parent>
  </parents>
  <author>
    <name>David Moreno</name>
    <email>david@axiombox.com</email>
  </author>
  <url>http://github.com/damog/rfeed/commit/711eca9248ec8e61fc1ff44f9d40594f4007f129</url>
  <id>711eca9248ec8e61fc1ff44f9d40594f4007f129</id>
  <committed-date>2009-03-20T10:19:34-07:00</committed-date>
  <authored-date>2009-03-20T10:19:34-07:00</authored-date>
  <message>adding terminator support; adding more validations, etc</message>
  <tree>a12b75a3d2d06246e422fbf20d33640e6b4658fd</tree>
  <committer>
    <name>David Moreno</name>
    <email>david@axiombox.com</email>
  </committer>
</commit>
