[gitg] Allow async thread functions to throw errors



commit e6dfaac72b463d3a90b3f8a3a1a26309902921e6
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Sun Jul 7 16:12:21 2013 +0200

    Allow async thread functions to throw errors

 libgitg/gitg-async.vala |   31 ++++++++++++++++++++-----------
 libgitg/gitg-stage.vala |   38 +++++++++++++++++++-------------------
 2 files changed, 39 insertions(+), 30 deletions(-)
---
diff --git a/libgitg/gitg-async.vala b/libgitg/gitg-async.vala
index a9d1599..15b52be 100644
--- a/libgitg/gitg-async.vala
+++ b/libgitg/gitg-async.vala
@@ -22,26 +22,35 @@ namespace Gitg
 
 public class Async
 {
-       public delegate void ThreadFunc();
+       public delegate void ThreadFunc() throws Error;
 
-       public static async void thread(ThreadFunc func)
+       public static async void thread(ThreadFunc func) throws Error
        {
                SourceFunc callback = thread.callback;
+               Error? err = null;
 
-               try
-               {
-                       var t = new Thread<void *>.try("gitg-status-enumerator", () => {
+               var t = new Thread<void *>.try("gitg-status-enumerator", () => {
+                       try
+                       {
                                func();
-                               Idle.add((owned)callback);
+                       }
+                       catch (Error e)
+                       {
+                               err = e;
+                       }
+
+                       Idle.add((owned)callback);
+                       return null;
+               });
 
-                               return null;
-                       });
+               yield;
 
-                       yield;
+               t.join();
 
-                       t.join();
+               if (err != null)
+               {
+                       throw err;
                }
-               catch {}
        }
 }
 
diff --git a/libgitg/gitg-stage.vala b/libgitg/gitg-stage.vala
index 9709109..c8b4259 100644
--- a/libgitg/gitg-stage.vala
+++ b/libgitg/gitg-stage.vala
@@ -92,14 +92,11 @@ public class Stage : Object
 
        private delegate void WithIndexFunc(Ggit.Index index) throws Error;
 
-       private void with_index(WithIndexFunc func)
+       private void with_index(WithIndexFunc func) throws Error
        {
                lock(d_index_mutex)
                {
-                       try
-                       {
-                               func(d_repository.get_index());
-                       } catch {}
+                       func(d_repository.get_index());
                }
        }
 
@@ -187,23 +184,26 @@ public class Stage : Object
        {
                string? errormsg = null;
 
-               yield Async.thread(() => {
-                       // First run the pre-commit hook
-                       var hook = new Gitg.Hook("pre-commit");
-
-                       setup_commit_hook_environment(hook, author);
+               try
+               {
+                       yield Async.thread(() => {
+                               // First run the pre-commit hook
+                               var hook = new Gitg.Hook("pre-commit");
 
-                       try
-                       {
-                               int status = hook.run_sync(d_repository);
+                               setup_commit_hook_environment(hook, author);
 
-                               if (status != 0)
+                               try
                                {
-                                       errormsg = string.joinv("\n", hook.output);
+                                       int status = hook.run_sync(d_repository);
+
+                                       if (status != 0)
+                                       {
+                                               errormsg = string.joinv("\n", hook.output);
+                                       }
                                }
-                       }
-                       catch (SpawnError e) {}
-               });
+                               catch (SpawnError e) {}
+                       });
+               } catch {}
 
                if (errormsg != null)
                {
@@ -232,7 +232,7 @@ public class Stage : Object
 
        private string commit_msg_hook(string         message,
                                       Ggit.Signature author,
-                                      Ggit.Signature committer) throws StageError
+                                      Ggit.Signature committer) throws Error
        {
                var hook = new Gitg.Hook("commit-msg");
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]