fix dialyzer issues

This commit is contained in:
Eric Merritt 2013-10-14 16:19:08 -07:00
parent 2e61eb481d
commit efdd2a1092
2 changed files with 19 additions and 16 deletions

View file

@ -49,9 +49,8 @@
-define(PREFIX, "===> "). -define(PREFIX, "===> ").
-record(state_t, {mod=?MODULE :: ec_log, -record(state_t, {log_level=0 :: int_log_level(),
log_level=0 :: int_log_level(), caller=api :: caller()}).
caller=api :: api | command_line}).
%%============================================================================ %%============================================================================
%% types %% types
@ -60,8 +59,11 @@
int_log_level/0, int_log_level/0,
atom_log_level/0, atom_log_level/0,
log_level/0, log_level/0,
caller/0,
log_fun/0]). log_fun/0]).
-type caller() :: api | command_line.
-type log_level() :: int_log_level() | atom_log_level(). -type log_level() :: int_log_level() | atom_log_level().
-type int_log_level() :: 0..3. -type int_log_level() :: 0..3.
@ -82,8 +84,9 @@
new(LogLevel) -> new(LogLevel) ->
new(LogLevel, api). new(LogLevel, api).
-spec new(log_level(), caller()) -> t().
new(LogLevel, Caller) when LogLevel >= 0, LogLevel =< 3 -> new(LogLevel, Caller) when LogLevel >= 0, LogLevel =< 3 ->
#state_t{mod=?MODULE, log_level=LogLevel, caller=Caller}; #state_t{log_level=LogLevel, caller=Caller};
new(AtomLogLevel, Caller) new(AtomLogLevel, Caller)
when AtomLogLevel =:= error; when AtomLogLevel =:= error;
AtomLogLevel =:= warn; AtomLogLevel =:= warn;
@ -165,7 +168,7 @@ warn(LogState, FormatString, Args) ->
%% @doc Execute the fun passed in if log level is as expected. %% @doc Execute the fun passed in if log level is as expected.
-spec log(t(), int_log_level(), log_fun()) -> ok. -spec log(t(), int_log_level(), log_fun()) -> ok.
log(#state_t{mod=?MODULE, log_level=DetailLogLevel}, LogLevel, Fun) log(#state_t{log_level=DetailLogLevel}, LogLevel, Fun)
when DetailLogLevel >= LogLevel -> when DetailLogLevel >= LogLevel ->
io:format("~s~n", [Fun()]); io:format("~s~n", [Fun()]);
log(_, _, _) -> log(_, _, _) ->
@ -174,7 +177,7 @@ log(_, _, _) ->
%% @doc when the module log level is less then or equal to the log level for the %% @doc when the module log level is less then or equal to the log level for the
%% call then write the log info out. When its not then ignore the call. %% call then write the log info out. When its not then ignore the call.
-spec log(t(), int_log_level(), string(), [any()]) -> ok. -spec log(t(), int_log_level(), string(), [any()]) -> ok.
log(#state_t{mod=?MODULE, log_level=DetailLogLevel}, LogLevel, FormatString, Args) log(#state_t{log_level=DetailLogLevel}, LogLevel, FormatString, Args)
when DetailLogLevel >= LogLevel, when DetailLogLevel >= LogLevel,
erlang:is_list(Args) -> erlang:is_list(Args) ->
io:format(FormatString, Args); io:format(FormatString, Args);
@ -184,7 +187,7 @@ log(_, _, _, _) ->
%% @doc return a boolean indicating if the system should log for the specified %% @doc return a boolean indicating if the system should log for the specified
%% levelg %% levelg
-spec should(t(), int_log_level() | any()) -> boolean(). -spec should(t(), int_log_level() | any()) -> boolean().
should(#state_t{mod=?MODULE, log_level=DetailLogLevel}, LogLevel) should(#state_t{log_level=DetailLogLevel}, LogLevel)
when DetailLogLevel >= LogLevel -> when DetailLogLevel >= LogLevel ->
true; true;
should(_, _) -> should(_, _) ->
@ -192,18 +195,18 @@ should(_, _) ->
%% @doc get the current log level as an integer %% @doc get the current log level as an integer
-spec log_level(t()) -> int_log_level(). -spec log_level(t()) -> int_log_level().
log_level(#state_t{mod=?MODULE, log_level=DetailLogLevel}) -> log_level(#state_t{log_level=DetailLogLevel}) ->
DetailLogLevel. DetailLogLevel.
%% @doc get the current log level as an atom %% @doc get the current log level as an atom
-spec atom_log_level(t()) -> atom_log_level(). -spec atom_log_level(t()) -> atom_log_level().
atom_log_level(#state_t{mod=?MODULE, log_level=?EC_ERROR}) -> atom_log_level(#state_t{log_level=?EC_ERROR}) ->
error; error;
atom_log_level(#state_t{mod=?MODULE, log_level=?EC_WARN}) -> atom_log_level(#state_t{log_level=?EC_WARN}) ->
warn; warn;
atom_log_level(#state_t{mod=?MODULE, log_level=?EC_INFO}) -> atom_log_level(#state_t{log_level=?EC_INFO}) ->
info; info;
atom_log_level(#state_t{mod=?MODULE, log_level=?EC_DEBUG}) -> atom_log_level(#state_t{log_level=?EC_DEBUG}) ->
debug. debug.
-spec format(t()) -> iolist(). -spec format(t()) -> iolist().

View file

@ -175,7 +175,7 @@ mkdir_path(Path) ->
%% @doc read a file from the file system. Provide UEX exeption on failure. %% @doc read a file from the file system. Provide UEX exeption on failure.
-spec read(FilePath::file:filename()) -> binary() | {error, Reason::term()}. -spec read(FilePath::file:filename()) -> {ok, binary()} | {error, Reason::term()}.
read(FilePath) -> read(FilePath) ->
%% Now that we are moving away from exceptions again this becomes %% Now that we are moving away from exceptions again this becomes
%% a bit redundant but we want to be backwards compatible as much %% a bit redundant but we want to be backwards compatible as much
@ -373,9 +373,9 @@ find_test() ->
{BaseDir, _SourceDir, {Name1, Name2, Name3, _NoName}} = setup_base_and_target(), {BaseDir, _SourceDir, {Name1, Name2, Name3, _NoName}} = setup_base_and_target(),
Result = find(BaseDir, "file[a-z]+\$"), Result = find(BaseDir, "file[a-z]+\$"),
?assertMatch(3, erlang:length(Result)), ?assertMatch(3, erlang:length(Result)),
?assert(lists:member(Name1, Result)), ?assertEqual(true, lists:member(Name1, Result)),
?assert(lists:member(Name2, Result)), ?assertEqual(true, lists:member(Name2, Result)),
?assert(lists:member(Name3, Result)), ?assertEqual(true, lists:member(Name3, Result)),
remove(BaseDir, [recursive]). remove(BaseDir, [recursive]).
-endif. -endif.