Skip to content

Commit

Permalink
Fix error information for code:get_coverage/2
Browse files Browse the repository at this point in the history
If `code:get_coverage(cover_line_id, Module)` failed, the first
argument would be unjustly blamed for the failure, instead of the
second argument ("the atom does not refer to a loaded module" or
"not loaded with coverage enabled").
  • Loading branch information
bjorng committed Aug 16, 2024
1 parent 94697ee commit 49288c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/kernel/src/erl_kernel_errors.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ format_code_error(get_coverage, [What,Module]) ->
Error = case What of
function -> [];
line -> [];
_ -> <<"must be one of: function or line">>
cover_line_id -> [];
_ -> coverage_level
end,
case Error of
[] ->
Expand Down Expand Up @@ -367,6 +368,8 @@ expand_error(bad_tracer) ->
<<"invalid tracer">>;
expand_error(coverage_disabled) ->
<<"not loaded with coverage enabled">>;
expand_error(coverage_level) ->
<<"must be one of: function, line, or cover_line_id">>;
expand_error(eq_in_list) ->
<<"\"=\" characters is not allowed in environment variable names">>;
expand_error(zero_in_list) ->
Expand Down
1 change: 1 addition & 0 deletions lib/kernel/test/code_coverage_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ error_info(_Config) ->
{get_coverage, [line,42]},
{get_coverage, [line,NotLoaded]},
{get_coverage, [line,?MODULE]},
{get_coverage, [cover_line_id,NotLoaded]},
{get_coverage, [whatever,?MODULE]},

{reset_coverage, [42]},
Expand Down

0 comments on commit 49288c0

Please sign in to comment.