Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Log unknown messages instead of crashing
  • Loading branch information
b20n authored and rnewson committed Aug 19, 2014
1 parent ba150cd commit 6efb035b7f181e3024b3cd87a1875c78f0bf2274
Showing 1 changed file with 6 additions and 3 deletions.
@@ -35,21 +35,24 @@ init([]) ->
{ok, #st{tracked = dict:new()}}.

handle_call(Msg, _From, State) ->
{stop, {unknown_call, Msg}, error, State}.
twig:log(notice, "~p received unknown call ~p", [?MODULE, Msg]),
{noreply, State}.

handle_cast({track, Pid, Name}, #st{tracked=Tracked}=State) ->
couch_stats:increment_counter(Name),
Ref = erlang:monitor(process, Pid),
{noreply, State#st{tracked=dict:store(Ref, Name, Tracked)}};
handle_cast(Msg, State) ->
{stop, {unknown_cast, Msg}, State}.
twig:log(notice, "~p received unknown cast ~p", [?MODULE, Msg]),
{noreply, State}.

handle_info({'DOWN', Ref, _, _, _}, #st{tracked=Tracked}=State) ->
Name = dict:fetch(Ref, Tracked),
couch_stats:decrement_counter(Name),
{noreply, State#st{tracked=dict:erase(Ref, Tracked)}};
handle_info(Msg, State) ->
{stop, {unknown_info, Msg}, State}.
twig:log(notice, "~p received unknown message ~p", [?MODULE, Msg]),
{noreply, State}.

terminate(_Reason, _State) ->
ok.

0 comments on commit 6efb035

Please sign in to comment.