Skip to content

Commit

Permalink
Sinking an unsuccessful Proc should throw.
Browse files Browse the repository at this point in the history
This means `run` anad `shell` in sink context will not fail silently
if they are not successful.
  • Loading branch information
jnthn committed Nov 5, 2015
1 parent 2e3da75 commit 289fdc5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/Exception.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2272,4 +2272,11 @@ my class X::Language::Unsupported is Exception {
}
}

my class X::Proc::Unsuccessful is Exception {
has $.proc;
method message() {
"The spawned process exited unsuccessfully (exit code: $.proc.exitcode())"
}
}

# vim: ft=perl6 expandtab sw=4
4 changes: 4 additions & 0 deletions src/core/Proc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ my class Proc {
multi method status(Proc:D:) { ($!exitcode +< 8) +| $!signal }
multi method Numeric(Proc:D:) { $!exitcode }
multi method Bool(Proc:D:) { $!exitcode == 0 }

method sink(--> Nil) {
X::Proc::Unsuccessful.new(:proc(self)).throw unless self;
}
}

sub run(*@args ($, *@), :$in = '-', :$out = '-', :$err = '-',
Expand Down

0 comments on commit 289fdc5

Please sign in to comment.