Skip to content

Commit

Permalink
Merge branch 'topic/instance_error' into 'master'
Browse files Browse the repository at this point in the history
Enhance GNATcheck error messages about instantiation process

Closes #364

See merge request eng/libadalang/langkit-query-language!314
  • Loading branch information
HugoGGuerrier committed Dec 2, 2024
2 parents adcbb23 + ca9bd7a commit eaa6b66
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 22 deletions.
21 changes: 12 additions & 9 deletions lkql_checker/src/gnatcheck-rules-rule_table.adb
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,8 @@ package body Gnatcheck.Rules.Rule_Table is
return;
elsif not Enable and then Instance = null then
Error
("rule instance doesn't exist, therefore, cannot be " &
"disabled: """ & To_String (Instance_Name) & """" &
("""" & To_String (Instance_Name) & """ is not enabled, " &
"therefore, cannot be disabled" &
Diag_Defined_At);
Bad_Rule_Detected := True;
return;
Expand Down Expand Up @@ -1162,8 +1162,11 @@ package body Gnatcheck.Rules.Rule_Table is
Expect (Instance_Object, "sourceMode");
Params_Object : JSON_Value := Instance_Object.Get ("arguments");

function Real_Instance_Name return String is
(if Instance_Name /= "" then Instance_Name else Rule_Name);
function Precise_Rule_Name return String is
("""" & Rule_Name & """" &
(if Instance_Name /= ""
then " (instance """ & Instance_Name & """)"
else ""));

procedure Error_In_Rule_File (Msg : String);
-- Emit a GNATcheck error when there is an error during the processing
Expand Down Expand Up @@ -1196,7 +1199,7 @@ package body Gnatcheck.Rules.Rule_Table is
pragma Unreferenced (Arg_Value);
begin
Error_In_Rule_File
("extra argument for instance " & Real_Instance_Name &
("extra argument for rule " & Precise_Rule_Name &
": '" & Arg_Name & "'");
end Report_Extra_Arg;

Expand Down Expand Up @@ -1270,15 +1273,15 @@ package body Gnatcheck.Rules.Rule_Table is
exception
when E : Field_Not_Found =>
Error_In_Rule_File
("missing parameter for instance " & Real_Instance_Name & ": '" &
Exception_Message (E) & "'");
("missing '" & Exception_Message (E) & "' parameter for rule " &
Precise_Rule_Name);
when E : Invalid_Type =>
Error_In_Rule_File
("invalid parameter for instance " & Real_Instance_Name & ": " &
("invalid parameter for rule " & Precise_Rule_Name & ": " &
Exception_Message (E));
when E : Invalid_Value =>
Error_In_Rule_File
("invalid parameter value for instance " & Real_Instance_Name &
("invalid parameter value for rule " & Precise_Rule_Name &
": " & Exception_Message (E));
end Process_Rule_Object;

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/gnatcheck/disabling_instance/test.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ main.adb:8:07: goto statement [cond_goto|goto_statements]
Disabling the wrong instance
============================

gnatcheck: rule instance doesn't exist, therefore, cannot be disabled: "goto_statements"
gnatcheck: "goto_statements" is not enabled, therefore, cannot be disabled
main.adb:3:04: goto statement [cond_goto|goto_statements]
>>>program returned status code 5
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ main.adb:17:08: actual parameter mismatch
Invalid type
============

gnatcheck: invalid parameter for instance actual_parameters: 'forbidden' should be a list of string tuples (invalid_type.lkql)
gnatcheck: invalid parameter for rule "actual_parameters": 'forbidden' should be a list of string tuples (invalid_type.lkql)
gnatcheck: No rule to check specified
try "gnatcheck --help" for more information.
>>>program returned status code 2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ main.adb:9:15: direct (in)equality
Invalid type
============

gnatcheck: invalid parameter for instance direct_equalities: 'actuals' value should be a list (invalid_type.lkql)
gnatcheck: invalid parameter for rule "direct_equalities": 'actuals' value should be a list (invalid_type.lkql)
gnatcheck: No rule to check specified
try "gnatcheck --help" for more information.
>>>program returned status code 2
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ main.adb:3:24: use of predefined OR for boolean type
Invalid type
============

gnatcheck: invalid parameter for instance goto_statements: 'only_unconditional' value should be a boolean (invalid_type.lkql)
gnatcheck: invalid parameter for rule "goto_statements": 'only_unconditional' value should be a boolean (invalid_type.lkql)
gnatcheck: No rule to check specified
try "gnatcheck --help" for more information.
>>>program returned status code 2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ main.adb:11:45: callback may propagate exceptions
Invalid type
============

gnatcheck: invalid parameter for instance exception_propagation_from_callbacks: 'callbacks' should be a list of string tuples (invalid_type.lkql)
gnatcheck: invalid parameter for rule "exception_propagation_from_callbacks": 'callbacks' should be a list of string tuples (invalid_type.lkql)
gnatcheck: No rule to check specified
try "gnatcheck --help" for more information.
>>>program returned status code 2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ no_header.adb:1:01: compilation unit does not start with header
Missing parameter
=================

gnatcheck: missing parameter for instance headers: 'header' (missing_param.lkql)
gnatcheck: missing 'header' parameter for rule "headers" (missing_param.lkql)
gnatcheck: No rule to check specified
try "gnatcheck --help" for more information.
>>>program returned status code 2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ main.adb:17:10: membership test
Invalid type
============

gnatcheck: invalid parameter for instance membership_tests: 'float_types_only' value should be a boolean (invalid_type.lkql)
gnatcheck: invalid parameter for rule "membership_tests": 'float_types_only' value should be a boolean (invalid_type.lkql)
gnatcheck: No rule to check specified
try "gnatcheck --help" for more information.
>>>program returned status code 2
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ main.ads:5:14: too many formal OUT parameters (3)
Missing parameter
=================

gnatcheck: missing parameter for instance maximum_out_parameters: 'n' (missing_param.lkql)
gnatcheck: missing 'n' parameter for rule "maximum_out_parameters" (missing_param.lkql)
gnatcheck: No rule to check specified
try "gnatcheck --help" for more information.
>>>program returned status code 2

Invalid type
============

gnatcheck: invalid parameter for instance maximum_out_parameters: 'n' value should be an integer (invalid_type.lkql)
gnatcheck: invalid parameter for rule "maximum_out_parameters": 'n' value should be an integer (invalid_type.lkql)
gnatcheck: No rule to check specified
try "gnatcheck --help" for more information.
>>>program returned status code 2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ main.adb:3:04: use of forbidden identifier
Missing parameter
=================

gnatcheck: missing parameter for instance name_clashes: 'dictionary_file' (missing_param.lkql)
gnatcheck: missing 'dictionary_file' parameter for rule "name_clashes" (missing_param.lkql)
gnatcheck: No rule to check specified
try "gnatcheck --help" for more information.
>>>program returned status code 2
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ main.adb:3:18: parameter out of order
Invalid argument value
======================

gnatcheck: invalid parameter value for instance parameters_out_of_order: 'order' should contains only 'in', 'defaulted_in', 'in_out', 'access' or 'out' strings (invalid_arg.lkql)
gnatcheck: invalid parameter value for rule "parameters_out_of_order": 'order' should contains only 'in', 'defaulted_in', 'in_out', 'access' or 'out' strings (invalid_arg.lkql)
gnatcheck: No rule to check specified
try "gnatcheck --help" for more information.
>>>program returned status code 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
val rules = @{
headers: {instance_name: "custom_instance"}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,23 @@ try "gnatcheck --help" for more information.
Missing mandatory parameter
===========================

gnatcheck: missing parameter for instance headers: 'header' (missing_param.lkql)
gnatcheck: missing 'header' parameter for rule "headers" (missing_param.lkql)
gnatcheck: No rule to check specified
try "gnatcheck --help" for more information.
>>>program returned status code 2

Missing mandatory parameter on instance
=======================================

gnatcheck: missing 'header' parameter for rule "headers" (instance "custom_instance") (missing_param_instance.lkql)
gnatcheck: No rule to check specified
try "gnatcheck --help" for more information.
>>>program returned status code 2

Extra parameter
===============

gnatcheck: extra argument for instance goto_statements: 'extra' (extra_param.lkql)
gnatcheck: extra argument for rule "goto_statements": 'extra' (extra_param.lkql)
>>>program returned status code 5

Multiple instance with the same name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ tests:
lkql_rule_file: not_existing.lkql
- label: Missing mandatory parameter
lkql_rule_file: missing_param.lkql
- label: Missing mandatory parameter on instance
lkql_rule_file: missing_param_instance.lkql
- label: Extra parameter
lkql_rule_file: extra_param.lkql
- label: Multiple instance with the same name
Expand Down

0 comments on commit eaa6b66

Please sign in to comment.