[libgee/wip/issue/23] Keep the original exception in Future.map/flat_map



commit 36e8e07cbe530b0296a8af71050e8d35c4251f48
Author: Brendan Long <self brendanlong com>
Date:   Sat Nov 4 12:06:25 2017 -0400

    Keep the original exception in Future.map/flat_map
    
    If a chain of maps fails, the final `exception` should be the actual
    exception, not a semi-useless `FutureError.EXCEPTION`.
    
    Fixes https://gitlab.gnome.org/GNOME/libgee/issues/23

 gee/future.vala | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/gee/future.vala b/gee/future.vala
index 654041b..9a004b2 100644
--- a/gee/future.vala
+++ b/gee/future.vala
@@ -134,6 +134,8 @@ public interface Gee.Future<G> : Object {
                wait_async.begin ((obj, res) => {
                        try {
                                promise.set_value (func (wait_async.end (res)));
+                       } catch (FutureError.EXCEPTION e) {
+                               promise.set_exception (this.exception);
                        } catch (Error ex) {
                                promise.set_exception ((owned)ex);
                        }
@@ -234,8 +236,15 @@ public interface Gee.Future<G> : Object {
        private static async void do_flat_map<A, B> (owned FlatMapFunc<B, A> func, Future<A> future, 
Promise<B> promise) {
                try {
                        A input = yield future.wait_async ();
-                       B output = yield func (input).wait_async ();
-                       promise.set_value ((owned)output);
+                       Future<B> output_future = func (input);
+                       try {
+                               B output = yield output_future.wait_async ();
+                               promise.set_value ((owned)output);
+                       } catch (FutureError.EXCEPTION e) {
+                               promise.set_exception (output_future.exception);
+                       }
+               } catch (FutureError.EXCEPTION e) {
+                       promise.set_exception (future.exception);
                } catch (Error ex) {
                        promise.set_exception ((owned)ex);
                }


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