From 36e8e07cbe530b0296a8af71050e8d35c4251f48 Mon Sep 17 00:00:00 2001 From: Brendan Long Date: Sat, 4 Nov 2017 12:06:25 -0400 Subject: 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 : 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 : Object { private static async void do_flat_map (owned FlatMapFunc func, Future future, Promise promise) { try { A input = yield future.wait_async (); - B output = yield func (input).wait_async (); - promise.set_value ((owned)output); + Future 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); } -- cgit v1.2.1