summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrendan Long <self@brendanlong.com>2017-11-04 12:06:25 -0400
committerRico Tzschichholz <ricotz@ubuntu.com>2022-09-17 13:44:31 +0200
commitabcf0b3bbdef094002a8202f6f2a6e6047d4d561 (patch)
tree94ef466931758864a6507ae6328db45255cab9b0
parent6cc0994484376453b110d8d76ef116cfb2f2693a (diff)
downloadlibgee-abcf0b3bbdef094002a8202f6f2a6e6047d4d561.tar.gz
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
-rw-r--r--gee/future.vala13
1 files changed, 11 insertions, 2 deletions
diff --git a/gee/future.vala b/gee/future.vala
index 7eb9001..1845447 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);
}