From 49288c0ab921905d518e02272b6ce17f2b1ceaa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 16 Aug 2024 09:20:25 +0200 Subject: [PATCH] Fix error information for `code:get_coverage/2` 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"). --- lib/kernel/src/erl_kernel_errors.erl | 5 ++++- lib/kernel/test/code_coverage_SUITE.erl | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/kernel/src/erl_kernel_errors.erl b/lib/kernel/src/erl_kernel_errors.erl index bd6c7acf5878..59a55b8590ee 100644 --- a/lib/kernel/src/erl_kernel_errors.erl +++ b/lib/kernel/src/erl_kernel_errors.erl @@ -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 [] -> @@ -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) -> diff --git a/lib/kernel/test/code_coverage_SUITE.erl b/lib/kernel/test/code_coverage_SUITE.erl index 0a79812c7727..0ccdb57c9b2f 100644 --- a/lib/kernel/test/code_coverage_SUITE.erl +++ b/lib/kernel/test/code_coverage_SUITE.erl @@ -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]},