Skip to content

Commit

Permalink
Change unknown call/cast/info Erlang message handling to use the same…
Browse files Browse the repository at this point in the history
… mechanism everywhere: Use "Unknown _ \"~w\"" as an Erlang string stop reason. Fix all internal services so cloudi_service_terminate/3 can accept a State variable as undefined, which occurs when cloudi_service_init/4 throws an exception (This is different from Erlang/OTP behaviours (they do not call terminate/2 if init/1 had an exception) because it allows easy handling of external state at termination, if any was partially initialized.).
  • Loading branch information
okeuday committed Apr 8, 2018
1 parent d9e4919 commit 7c52ecd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/cloudi_http_cowboy_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
%%%
%%% @author Michael Truog <mjtruog at protonmail dot com>
%%% @copyright 2012-2018 Michael Truog
%%% @version 1.7.3 {@date} {@time}
%%% @version 1.7.4 {@date} {@time}
%%%------------------------------------------------------------------------

-module(cloudi_http_cowboy_handler).
Expand Down Expand Up @@ -104,7 +104,7 @@ init(_Transport, Req0,
{ok, Req1, State}
end;
{Upgrade, Req1} ->
?LOG_ERROR("Unknown protocol: ~p", [Upgrade]),
?LOG_ERROR("Unknown protocol: ~w", [Upgrade]),
{shutdown, Req1, State}
end;
init(_Transport, Req,
Expand Down
11 changes: 6 additions & 5 deletions src/cloudi_service_http_cowboy.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
%%%
%%% MIT License
%%%
%%% Copyright (c) 2012-2017 Michael Truog <mjtruog at protonmail dot com>
%%% Copyright (c) 2012-2018 Michael Truog <mjtruog at protonmail dot com>
%%%
%%% Permission is hereby granted, free of charge, to any person obtaining a
%%% copy of this software and associated documentation files (the "Software"),
Expand All @@ -30,8 +30,8 @@
%%% DEALINGS IN THE SOFTWARE.
%%%
%%% @author Michael Truog <mjtruog at protonmail dot com>
%%% @copyright 2012-2017 Michael Truog
%%% @version 1.7.2 {@date} {@time}
%%% @copyright 2012-2018 Michael Truog
%%% @version 1.7.4 {@date} {@time}
%%%------------------------------------------------------------------------

-module(cloudi_service_http_cowboy).
Expand Down Expand Up @@ -540,9 +540,10 @@ cloudi_service_handle_info({update, UpdateDelaySeconds},
{update, UpdateDelaySeconds}),
{noreply, State#state{handler_state = NewHandlerState}};
cloudi_service_handle_info(Request, State, _Dispatcher) ->
?LOG_WARN("Unknown info \"~p\"", [Request]),
{noreply, State}.
{stop, cloudi_string:format("Unknown info \"~w\"", [Request]), State}.

cloudi_service_terminate(_Reason, _Timeout, undefined) ->
ok;
cloudi_service_terminate(_Reason, _Timeout,
#state{service = Service}) ->
try cowboy:stop_listener(Service)
Expand Down

0 comments on commit 7c52ecd

Please sign in to comment.