Subject: Re: [sup-devel] [PATCH] Catch errors while saving a message to disk for editing

From: Sascha Silbe <[email-masked]>
Date: Sat, 02 Jul 2011 23:54:04 +0200

Excerpts from Alexander Shulgin's message of Sat Jul 02 22:28:27 +0200 2011:

> > -  def edit_message
> > -    @file = Tempfile.new "sup.#{self.class.name.gsub(/.*::/, '').camel_to_hyphy}"
> > +  def save_message_to_file
> 
> Didn't you mean 'write_message_to_file' here instead?

Oops, yes. I forgot to update the index after fixing this (there are
other, unrelated changes in the working directory that I didn't want to
commit, so I didn't use "git commit -a" as usual). Will post a new
version. Thanks for spotting this!

Sascha

-- 
http://sascha.silbe.org/
http://www.infra-silbe.de/
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Alexander Shulgin <[email-masked]>
Date: Sat, 2 Jul 2011 23:28:27 +0300

On Sat, Jul 2, 2011 at 18:06, Sascha Silbe <[email-masked]> wrote:

>  lib/sup/modes/edit-message-mode.rb |   24 +++++++++++++++++-------
>  1 files changed, 17 insertions(+), 7 deletions(-)
>
> diff --git a/lib/sup/modes/edit-message-mode.rb b/lib/sup/modes/edit-message-mode.rb
> index 5ed7833..256e314 100644
> --- a/lib/sup/modes/edit-message-mode.rb
> +++ b/lib/sup/modes/edit-message-mode.rb
> @@ -172,12 +172,21 @@ def edit_to; edit_field "To" end
>   def edit_cc; edit_field "Cc" end
>   def edit_subject; edit_field "Subject" end
>
> -  def edit_message

> +    @file = Tempfile.new ["sup.#{self.class.name.gsub(/.*::/, '').camel_to_hyphy}", ".eml"]
>     @file.puts format_headers(@header - NON_EDITABLE_HEADERS).first
>     @file.puts
>     @file.puts @body.join("\n")
>     @file.close
> +  end
> +
> +  def edit_message
> +    begin
> +      write_message_to_file
> +    rescue SystemCallError => e
> +      BufferManager.flash "Can't save message to file: #{e.message}"
> +      return
> +    end
>
>     editor = $config[:editor] || ENV['EDITOR'] || "/usr/bin/vi"
>
[snip]

---

From: Sascha Silbe <[email-masked]>
Date: Sat, 2 Jul 2011 17:06:54 +0200

Running out of disk space in /tmp caused sup to crash with the following
exception:

--- Errno::ENOSPC from thread: main
No space left on device - /tmp/sascha_silbe/sup.reply-mode20110702-31427-rtg4kl-0
/usr/lib/ruby/1.8/tempfile.rb:97:in `close'
/usr/lib/ruby/1.8/tempfile.rb:97:in `_close'
/usr/lib/ruby/1.8/tempfile.rb:112:in `close'
./lib/sup/modes/edit-message-mode.rb:180:in `edit_message'
./lib/sup/mode.rb:59:in `send'
./lib/sup/mode.rb:59:in `handle_input'
./lib/sup/buffer.rb:278:in `handle_input'
bin/sup:271

Signed-off-by: Sascha Silbe <[email-masked]>
---
 lib/sup/modes/edit-message-mode.rb |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

-  def edit_message

@@ -197,11 +206,12 @@ def edit_message
   end
 
   def edit_message_async
-    @file = Tempfile.new ["sup.#{self.class.name.gsub(/.*::/, '').camel_to_hyphy}", ".eml"]
-    @file.puts format_headers(@header - NON_EDITABLE_HEADERS).first
-    @file.puts
-    @file.puts @body.join("\n")
-    @file.close
+    begin
+      write_message_to_file
+    rescue SystemCallError => e
+      BufferManager.flash "Can't save message to file: #{e.message}"
+      return
+    end
 
     @mtime = File.mtime @file.path
 
-- 
1.7.4.1

---

From: Sascha Silbe <[email-masked]>
Date: Sat, 2 Jul 2011 23:56:16 +0200

Signed-off-by: Sascha Silbe <[email-masked]>
---
 v1->v2: fix typo (save_message_to_file vs. write_message_to_file)

index 5ed7833..4387f7b 100644

-  def edit_message
+      save_message_to_file

   def edit_message_async
+      save_message_to_file

--
1.7.4.1