Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Give promise-related exceptions more information
some of that is not visible in the error message, but it might still be useful
for a deeper analysis
  • Loading branch information
moritz committed Dec 21, 2014
1 parent 039652b commit 4d9771f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/core/Promise.pm
Expand Up @@ -7,9 +7,12 @@ my class X::Promise::Combinator is Exception {
method message() { "Can only use $!combinator to combine other Promise objects" }
}
my class X::Promise::CauseOnlyValidOnBroken is Exception {
method message() { "Can only call cause on a broken promise" }
has $.promise;
has $.status;
method message() { "Can only call cause on a broken promise (status: $.status)" }
}
my class X::Promise::Vowed is Exception {
has $.promise;
method message() { "Access denied to keep/break this Promise; already vowed" }
}
my class Promise {
Expand Down Expand Up @@ -45,7 +48,7 @@ my class Promise {
nqp::lock($!lock);
if $!vow_taken {
nqp::unlock($!lock);
X::Promise::Vowed.new.throw
X::Promise::Vowed.new(promise => self).throw
}
my $vow := nqp::create(Vow);
nqp::bindattr($vow, Vow, '$!promise', self);
Expand Down Expand Up @@ -120,10 +123,14 @@ my class Promise {
}

method cause(Promise:D:) {
if $!status == Broken {
my $status = $!status;
if $status == Broken {
$!result
} else {
X::Promise::CauseOnlyValidOnBroken.new.throw
X::Promise::CauseOnlyValidOnBroken.new(
promise => self,
status => $status,
).throw
}
}

Expand Down

0 comments on commit 4d9771f

Please sign in to comment.