Skip to content

Commit

Permalink
Fix dialyzer warnings in supervisor
Browse files Browse the repository at this point in the history
Dialyzer complained over a mismatch between the callback spec of
Mod:code_change in gen_server and the spec of supervisor:code_change
(which is the implementation of a gen_server Mod:code_change).

This commit changes the callback spec to allow {error,Reason} as
return value. Also, release_handler is updated to handle this return
value.
  • Loading branch information
sirihansen committed Nov 29, 2011
1 parent 2b36dd7 commit 038b9dd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
15 changes: 10 additions & 5 deletions lib/sasl/src/release_handler_1.erl
Expand Up @@ -505,15 +505,20 @@ resume(Pids) ->

change_code(Pids, Mod, Vsn, Extra, Timeout) ->
Fun = fun(Pid) ->
case Timeout of
default ->
ok = sys:change_code(Pid, Mod, Vsn, Extra);
_Else ->
ok = sys:change_code(Pid, Mod, Vsn, Extra, Timeout)
case sys_change_code(Pid, Mod, Vsn, Extra, Timeout) of
ok ->
ok;
{error,Reason} ->
throw({code_change_failed,Pid,Mod,Vsn,Reason})
end
end,
lists:foreach(Fun, Pids).

sys_change_code(Pid, Mod, Vsn, Extra, default) ->
sys:change_code(Pid, Mod, Vsn, Extra);
sys_change_code(Pid, Mod, Vsn, Extra, Timeout) ->
sys:change_code(Pid, Mod, Vsn, Extra, Timeout).

stop(Mod, Procs) ->
lists:zf(fun({undefined, _Name, _Pid, _Mods}) ->
false;
Expand Down
10 changes: 7 additions & 3 deletions lib/stdlib/doc/src/gen_server.xml
Expand Up @@ -4,7 +4,7 @@
<erlref>
<header>
<copyright>
<year>1996</year><year>2010</year>
<year>1996</year><year>2011</year>
<holder>Ericsson AB. All Rights Reserved.</holder>
</copyright>
<legalnotice>
Expand Down Expand Up @@ -570,13 +570,14 @@ gen_server:abcast -----> Module:handle_cast/2
</desc>
</func>
<func>
<name>Module:code_change(OldVsn, State, Extra) -> {ok, NewState}</name>
<name>Module:code_change(OldVsn, State, Extra) -> {ok, NewState} | {error, Reason}</name>
<fsummary>Update the internal state during upgrade/downgrade.</fsummary>
<type>
<v>OldVsn = Vsn | {down, Vsn}</v>
<v>&nbsp;&nbsp;Vsn = term()</v>
<v>State = NewState = term()</v>
<v>Extra = term()</v>
<v>Reason = term()</v>
</type>
<desc>
<p>This function is called by a gen_server when it should
Expand All @@ -595,7 +596,10 @@ gen_server:abcast -----> Module:handle_cast/2
<p><c>State</c> is the internal state of the gen_server.</p>
<p><c>Extra</c> is passed as-is from the <c>{advanced,Extra}</c>
part of the update instruction.</p>
<p>The function should return the updated internal state.</p>
<p>If successful, the function shall return the updated
internal state.</p>
<p>If the function returns <c>{error,Reason}</c>, the ongoing
upgrade will fail and roll back to the old release.</p>
</desc>
</func>
<func>
Expand Down
2 changes: 1 addition & 1 deletion lib/stdlib/src/gen_server.erl
Expand Up @@ -134,7 +134,7 @@
term().
-callback code_change(OldVsn :: (term() | {down, term()}), State :: term(),
Extra :: term()) ->
{ok, NewState :: term()}.
{ok, NewState :: term()} | {error, Reason :: term()}.

%%% -----------------------------------------------------------------
%%% Starts a generic server.
Expand Down
2 changes: 1 addition & 1 deletion lib/stdlib/src/supervisor.erl
Expand Up @@ -37,7 +37,7 @@

%%--------------------------------------------------------------------------

-type child() :: pid() | 'undefined'.
-type child() :: 'undefined' | pid() | [pid()].
-type child_id() :: term().
-type mfargs() :: {M :: module(), F :: atom(), A :: [term()] | undefined}.
-type modules() :: [module()] | 'dynamic'.
Expand Down

0 comments on commit 038b9dd

Please sign in to comment.