]> git.cworth.org Git - sup/commitdiff
yet more error handling updates
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 2 Apr 2007 05:11:49 +0000 (05:11 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 2 Apr 2007 05:11:49 +0000 (05:11 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@366 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/imap.rb
lib/sup/maildir.rb
lib/sup/mbox/loader.rb
lib/sup/mbox/ssh-file.rb
lib/sup/mbox/ssh-loader.rb
lib/sup/mode.rb

index c37bb5a5596f91fb598de7c9674111b3a6135ee0..0f539eea4f7fa26e5f1bd61ca714d84e2601825c 100644 (file)
@@ -240,7 +240,7 @@ private
         end
         raise
       end
-    rescue Net, SocketError, Net::IMAP::Error, SystemCallError => e
+    rescue SocketError, Net::IMAP::Error, SystemCallError, IOError => e
       raise FatalSourceError, "While communicating with IMAP server: #{e.message}"
     end
   end
index c6aa69b03926afa66da567b2bbfb3fcdd8a03890..012663d85eb7739173184c09009de42e9f08e106 100644 (file)
@@ -75,7 +75,7 @@ class Maildir < Source
         end
         [ids.sort, ids_to_fns]
       end
-    rescue SystemCallError => e
+    rescue SystemCallError, IOError => e
       raise FatalSourceError, "Problem scanning Maildir directories: #{e.message}."
     end
     
@@ -116,7 +116,7 @@ private
     fn = @ids_to_fns[id] or raise OutOfSyncSourceError, "No such id: #{id.inspect}."
     begin
       File.open(fn) { |f| yield f }
-    rescue SystemCallError => e
+    rescue SystemCallError, IOError => e
       raise FatalSourceError, "Problem reading file for id #{id.inspect}: #{fn.inspect}: #{e.message}."
     end
   end
index c96bd351ffd6c69dec33bced226a6efc54cccf5c..e6fd1d497d44d2b75c3658b7afcc47c64d9c9cdc 100644 (file)
@@ -15,7 +15,7 @@ class Loader < Source
     when String
       uri = URI(uri_or_fp)
       raise ArgumentError, "not an mbox uri" unless uri.scheme == "mbox"
-      raise ArgumentError, "mbox uri cannot have a host: #{uri.host}" if uri.host
+      raise ArgumentError, "mbox uri ('#{uri}') cannot have a host: #{uri.host}" if uri.host
       ## heuristic: use the filename as a label, unless the file
       ## has a path that probably represents an inbox.
       @labels << File.basename(uri.path).intern unless File.dirname(uri.path) =~ /\b(var|usr|spool)\b/
@@ -112,7 +112,7 @@ class Loader < Source
           next_offset = @f.tell
         end
       end
-    rescue SystemCallError => e
+    rescue SystemCallError, IOError => e
       raise FatalSourceError, "Error reading #{@f.path}: #{e.message}"
     end
 
index 6e91c2089f96c77b62430077120d0d0c63a6db27..25074beb345493cbfb3dcd21a00150305bfb7c18 100644 (file)
@@ -106,14 +106,12 @@ class SSHFile
     @file_size = nil
     @offset = 0
     @say_id = nil
-    @broken_msg = nil
     @shell = nil
     @shell_mutex = nil
     @buf_mutex = Mutex.new
   end
 
   def to_s; "mbox+ssh://#@host/#@fn"; end ## TODO: remove this EVILness
-  def broken?; !@broken_msg.nil?; end
 
   def connect
     do_remote nil
@@ -164,7 +162,6 @@ private
   end
 
   def unsafe_connect
-    raise SSHFileError, @broken_msg if broken?
     return if @shell
 
     @key = [@host, @ssh_opts[:username]]
@@ -172,14 +169,13 @@ private
       @shell, @shell_mutex = @@shells_mutex.synchronize do
         unless @@shells.member? @key
           say "Opening SSH connection to #{@host} for #@fn..."
-          #raise SSHFileError, "simulated SSH file error"
           session = Net::SSH.start @host, @ssh_opts
           say "Starting SSH shell..."
           @@shells[@key] = [session.shell.sync, Mutex.new]
         end
         @@shells[@key]
       end
-
+      
       say "Checking for #@fn..."
       @shell_mutex.synchronize { raise Errno::ENOENT, @fn unless @shell.test("-e #@fn").status == 0 }
     ensure
@@ -190,29 +186,24 @@ private
   def do_remote cmd, expected_size=0
     retries = 0
     result = nil
-    begin
-      begin
-        unsafe_connect
-        if cmd
-          # MBox::debug "sending command: #{cmd.inspect}"
-          result = @shell_mutex.synchronize { x = @shell.send_command cmd; sleep 0.25; x }
-          raise SSHFileError, "Failure during remote command #{cmd.inspect}: #{(result.stderr || result.stdout || "")[0 .. 100]}" unless result.status == 0
-        end
 
-        ## Net::SSH::Exceptions seem to happen every once in a while for
-        ## no good reason.
-      rescue Net::SSH::Exception, *RECOVERABLE_ERRORS
-        if (retries += 1) <= 3
-          @@shells_mutex.synchronize do
-            @shell = nil
-            @@shells[@key] = nil
-          end
-          retry
+    begin
+      unsafe_connect
+      if cmd
+        # MBox::debug "sending command: #{cmd.inspect}"
+        result = @shell_mutex.synchronize { x = @shell.send_command cmd; sleep 0.25; x }
+        raise SSHFileError, "Failure during remote command #{cmd.inspect}: #{(result.stderr || result.stdout || "")[0 .. 100]}" unless result.status == 0
+      end
+      ## Net::SSH::Exceptions seem to happen every once in a while for
+      ## no good reason.
+    rescue Net::SSH::Exception, *RECOVERABLE_ERRORS
+      if (retries += 1) <= 3
+        @@shells_mutex.synchronize do
+          @shell = nil
+          @@shells[@key] = nil
         end
-        raise
+        retry
       end
-    rescue Net::SSH::Exception, SSHFileError, SystemCallError => e
-      @broken_msg = e.message
       raise
     end
 
index 4ea10d890d58b942319dae12b7a1e9d15b0cc9ef..f9e226af25e4e900bcaed0ab7ea351b2da89fe55 100644 (file)
@@ -3,10 +3,6 @@ require 'net/ssh'
 module Redwood
 module MBox
 
-## this is slightly complicated because SSHFile (and thus @f or
-## @loader) can throw a variety of exceptions, and we need to catch
-## those, reraise them as SourceErrors, and set ourselves as broken.
-
 class SSHLoader < Source
   attr_accessor :username, :password
 
@@ -39,7 +35,6 @@ class SSHLoader < Source
   def filename; @parsed_uri.path[1..-1] end
 
   def next
-    return if broken?
     safely do
       offset, labels = @loader.next
       self.cur_offset = @loader.cur_offset # superclass keeps @cur_offset which is used by yaml
@@ -60,11 +55,9 @@ class SSHLoader < Source
   def safely
     begin
       yield
-    rescue Net::SSH::Exception, SocketError, SSHFileError, SystemCallError => e
+    rescue Net::SSH::Exception, SocketError, SSHFileError, SystemCallError, IOError => e
       m = "error communicating with SSH server #{host} (#{e.class.name}): #{e.message}"
-      Redwood::log m
-      self.broken_msg = @loader.broken_msg = m
-      raise SourceError, m
+      raise FatalSourceError, m
     end
   end
 
index 640fbbecbd03f3b0f91df84b23119707d96b7a0d..7d437e2237c19eeb3c85fcd2700fe119230bde1e 100644 (file)
@@ -81,7 +81,7 @@ EOS
     begin
       File.open(fn, "w") { |f| yield f }
       BufferManager.flash "Successfully wrote #{fn}."
-    rescue SystemCallError => e
+    rescue SystemCallError, IOError => e
       BufferManager.flash "Error writing to file: #{e.message}"
     end
   end