badpid: use error exception instead of exit

A badpid exception should be an error:

    OSPid = try alcove:getpid(Drv, [1,2,3])
    catch
        error:badpid -> handle_error(...)
    end.
This commit is contained in:
Michael Santos
2015-08-04 09:34:07 -04:00
parent 2379cd04a2
commit 9eda1ce49a
3 changed files with 11 additions and 11 deletions

View File

@@ -194,34 +194,34 @@ call_reply(Drv, Pids, false, Timeout) ->
{alcove_ctl, Drv, Pids, fdctl_closed} ->
ok;
{alcove_ctl, Drv, _Pids, badpid} ->
exit(badpid);
erlang:error(badpid);
{alcove_call, Drv, Pids, Event} ->
Event
after
Timeout ->
exit(timeout)
erlang:error(timeout)
end;
call_reply(Drv, Pids, true, Timeout) ->
receive
{alcove_ctl, Drv, Pids, fdctl_closed} ->
call_reply(Drv, Pids, true, Timeout);
{alcove_event, Drv, Pids, {termsig,_} = Event} ->
exit(Event);
erlang:error(Event);
{alcove_event, Drv, Pids, {exit_status,_} = Event} ->
exit(Event);
erlang:error(Event);
{alcove_ctl, Drv, _Pids, badpid} ->
exit(badpid);
erlang:error(badpid);
{alcove_call, Drv, Pids, Event} ->
Event
after
Timeout ->
exit(timeout)
erlang:error(timeout)
end.
reply(Drv, Pids, Type, Timeout) ->
receive
{alcove_ctl, Drv, _Pids, badpid} ->
exit(badpid);
erlang:error(badpid);
{Type, Drv, Pids, Event} ->
Event
after

View File

@@ -73,7 +73,7 @@ kill(#state{pid = Drv}) ->
[
?_assertEqual(Pid, Reply0),
?_assertEqual({'EXIT',{termsig,sigsys}}, Reply1),
?_assertMatch({'EXIT',{{termsig,sigsys},_}}, Reply1),
?_assertEqual({error, esrch}, Reply2)
].

View File

@@ -433,9 +433,9 @@ badpid(#state{pid = Drv}) ->
"/bin/sh", ["/bin/sh", "-c", "echo > /dev/null"])),
[
?_assertEqual({'EXIT',badpid}, Reply0),
?_assertEqual({'EXIT',badpid}, Reply1),
?_assertEqual({'EXIT',badpid}, Reply2)
?_assertMatch({'EXIT',{badpid,_}}, Reply0),
?_assertMatch({'EXIT',{badpid,_}}, Reply1),
?_assertMatch({'EXIT',{badpid,_}}, Reply2)
].
signal(#state{pid = Drv}) ->