Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve user experience with better manifest errors messages #1229

Merged
merged 4 commits into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
build:
name: CI on macOS

runs-on: macos-latest
runs-on: macos-10.15

steps:
- name: Check out repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
matrix:
os:
- macos-latest
- macos-10.15
- ubuntu-latest
- windows-latest

Expand Down
6 changes: 4 additions & 2 deletions src/alire/alire-conditional_trees-toml_load.adb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ package body Alire.Conditional_Trees.TOML_Load is
then
if Strict then
Case_Table.Recoverable_Error
("invalid enumeration value: " & Item_Key);
("invalid enumeration value: '" & Item_Key &
"'." & Map.Base.Suggestion (Item_Key));
else
Trace.Debug
(Errors.Stack
("unknown enumeration value: " & Item_Key));
("unknown enumeration value: " & Item_Key &
"'." & Map.Base.Suggestion (Item_Key)));
end if;
end if;
end loop;
Expand Down
8 changes: 8 additions & 0 deletions src/alire/alire-expressions-enums.adb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ package body Alire.Expressions.Enums is
function Is_Valid (This : Enum_Values; Image : String) return Boolean
is (This.Values.Contains (TOML_Adapters.Tomify (Image)));

overriding
function Possible_Values (This : Enum_Values) return AAA.Strings.Vector is
Result : AAA.Strings.Vector;
begin
Result.Prepend (This.Values);
return Result;
end Possible_Values;

begin
declare
Values : Enum_Values;
Expand Down
11 changes: 11 additions & 0 deletions src/alire/alire-expressions.adb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ with Ada.Containers.Indefinite_Ordered_Maps;
with Alire.Errors;
with Alire.TOML_Adapters;
with Alire.Utils;
with Alire.Utils.Did_You_Mean;

package body Alire.Expressions is

Expand Down Expand Up @@ -43,6 +44,16 @@ package body Alire.Expressions is
Key_Variables_Image (Variables) & ")")
else Variable_Values (Key (This)).Is_Valid (Value));

----------------
-- Suggestion --
----------------

function Suggestion (This : Variable; Value : String) return String is
begin
return Utils.Did_You_Mean.Suggestion
(Value, Variable_Values (Key (This)).Possible_Values);
end Suggestion;

-----------------------
-- Register_Variable --
-----------------------
Expand Down
5 changes: 5 additions & 0 deletions src/alire/alire-expressions.ads
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ package Alire.Expressions with Preelaborate is
function Is_Valid (This : Variable; Value : String) return Boolean;
-- Says if Value is among the values in This

function Suggestion (This : Variable; Value : String) return String;
-- Return a " Did you mean?" message for a given invalid value

function Key (This : Variable) return String;
-- The key that is used in TOML files for this variable

Expand Down Expand Up @@ -58,6 +61,8 @@ private
function Is_Valid (V : Values; Image : String) return Boolean is abstract;
-- Say if a value, given as its string image, matches a value of a type

function Possible_Values (V : Values) return AAA.Strings.Vector is abstract;

procedure Register (Var_Key : String;
Var_Name : String;
Var_Values : Values'Class);
Expand Down
9 changes: 8 additions & 1 deletion src/alire/alire-properties-actions-runners.adb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
with AAA.Enum_Tools;
with Alire.Utils.Did_You_Mean;

package body Alire.Properties.Actions.Runners is

Expand Down Expand Up @@ -61,6 +62,11 @@ package body Alire.Properties.Actions.Runners is
Moment : Moments;

function Is_Valid is new AAA.Enum_Tools.Is_Valid (Moments);

function Suggestion
is new Utils.Did_You_Mean.Enum_Suggestion
(Moments, Utils.Did_You_Mean.Tomify);

begin
if not From.Pop (TOML_Keys.Action_Type, Kind) then
From.Checked_Error ("action type missing");
Expand All @@ -81,7 +87,8 @@ package body Alire.Properties.Actions.Runners is
end if;

if not Is_Valid (TOML_Adapters.Adafy (Kind.As_String)) then
From.Checked_Error ("action type is invalid: " & Kind.As_String);
From.Checked_Error ("action type is invalid: '" & Kind.As_String &
"'." & Suggestion (Kind.As_String));
else
Moment := Moments'Value (TOML_Adapters.Adafy (Kind.As_String));
end if;
Expand Down
36 changes: 26 additions & 10 deletions src/alire/alire-properties-build_profiles.adb
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
with Alire.TOML_Keys;

with Alire.Utils.Switches; use Alire.Utils.Switches;
with Alire.Utils.Did_You_Mean;

package body Alire.Properties.Build_Profiles is

function Profile_Kind_Suggestion
is new Utils.Did_You_Mean.Enum_Suggestion
(Profile_Kind, Utils.Did_You_Mean.Lower_Case);

-----------------------
-- Check_Profile_Str --
-----------------------

procedure Check_Profile_Str (From : TOML_Adapters.Key_Queue;
Str, Crate_Str : String)
is
Unused : Profile_Kind;
begin
Unused := Profile_Kind'Value (Str);
exception
when Constraint_Error =>
From.Checked_Error
("Invalid build profile name: '" & Str
& "' for '" & Crate_Str & "'." &
Profile_Kind_Suggestion (Str));
end Check_Profile_Str;

-----------
-- Image --
-----------
Expand Down Expand Up @@ -72,6 +95,7 @@ package body Alire.Properties.Build_Profiles is
("Multiple definition of wildcard (""*"")" &
" build profile");
else
Check_Profile_Str (From, Profile_Str, Crate_Str);
Var.Wildcard_Found := True;
end if;

Expand All @@ -81,16 +105,8 @@ package body Alire.Properties.Build_Profiles is
Error_In_Name (Crate_Str) & ")");
else

declare
Unused : Profile_Kind;
begin
Unused := Profile_Kind'Value (Profile_Str);
exception
when Constraint_Error =>
From.Checked_Error
("Invalid build profile name: '" & Profile_Str
& "' for '" & Crate_Str & "'");
end;
Check_Profile_Str (From, Profile_Str, Crate_Str);

end if;
end;

Expand Down
Loading