From 5793ef6640a44c36186f006ac011366809558fe6 Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Fri, 6 Nov 2020 14:06:24 +0100 Subject: [PATCH] fix(emqx_mod_sup): Dialyzer warning All the callers of start_child API are discarding the return value. --- src/emqx_mod_sup.erl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/emqx_mod_sup.erl b/src/emqx_mod_sup.erl index b5512013c..0f19a0cf5 100644 --- a/src/emqx_mod_sup.erl +++ b/src/emqx_mod_sup.erl @@ -40,11 +40,13 @@ start_link() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []). +-spec start_child(supervisor:child_spec()) -> ok. start_child(ChildSpec) when is_map(ChildSpec) -> - supervisor:start_child(?MODULE, ChildSpec). + assert_started(supervisor:start_child(?MODULE, ChildSpec)). +-spec start_child(atom(), atom()) -> ok. start_child(Mod, Type) when is_atom(Mod) andalso is_atom(Type) -> - supervisor:start_child(?MODULE, ?CHILD(Mod, Type)). + assert_started(supervisor:start_child(?MODULE, ?CHILD(Mod, Type))). -spec(stop_child(any()) -> ok | {error, term()}). stop_child(ChildId) -> @@ -61,3 +63,12 @@ init([]) -> ok = emqx_tables:new(emqx_modules, [set, public, {write_concurrency, true}]), {ok, {{one_for_one, 10, 100}, []}}. +%%-------------------------------------------------------------------- +%% Internal functions +%%-------------------------------------------------------------------- + +assert_started({ok, _Pid}) -> ok; +assert_started({ok, _Pid, _Info}) -> ok; +assert_started({error, {already_tarted, _Pid}}) -> ok; +assert_started({error, Reason}) -> erlang:error(Reason). +