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 error messages #98

Closed

Conversation

yannham
Copy link
Member

@yannham yannham commented Jul 2, 2020

Partly address #92. Depends on #97. This PR adds more specific variants to the error type EvalError, and moves the elaboration of error messages to a dedicated location, namely the implementation of the trait defined in #97. The evaluation code now passes elementary data through these variants rather than building error messages itself, wherever possible. The intended result is that error messages are more consistent and easier to improve in the future.

Examples

Doing so, error messages have also been revamped although was not the main focus, and can still be improved. Blame error messages have not yet been modified. Here are a few examples of messages before and after this PR:

Before

% nickel <<< '"a" 1'
Evaluation didn't finished, found error:
The term Str("a") was applied to RichTerm { term: Num(1.0), pos: Some((882, 883)) }

% nickel <<< 'merge 2 {a=1;}'
Evaluation didn't finished, found error:
Could not merge Num(2.0) and Record({Ident("a"): RichTerm { term: Num(1.0), pos: Some((889, 890)) }})

% nickel <<< 'blame 1'
Evaluation didn't finished, found error:
Expected Label, got Num(1.0)

% nickel <<< '{a=1;}.b'
Evaluation didn't finished, found error:
Record didn't have field Ident("b")

Now

% nickel <<< '"a" 1'
Error: At <stdin> line 1, columns 1-6: tried to apply "a" (from <stdin> line 1, columns 1-4) to 1 (from <stdin> line 1, columns 5-6),
but this is not a function.`

% nickel <<< 'merge 2 {a=1;}'
Error: At <stdin> line 1, columns 1-15: could not merge 2 (from <stdin> line 1, columns 7-8) with { ... } (from <stdin> line 1, column
s 9-15)

% nickel <<< 'blame 1'
Error: At <stdin> line 1, columns 7-8: expected Label, got Num (blame)

% nickel <<< '{a=1;}.b'
Error: At <stdin> line 1, columns 1-9: field "b" is required by (.), but was not found in the record at <stdin> line 1, columns 1-7

@yannham yannham force-pushed the feature/improve-error-messages branch from f7a3eb3 to 109677e Compare July 7, 2020 15:15
@yannham
Copy link
Member Author

yannham commented Jul 21, 2020

Superseded by #102.

@yannham yannham closed this Jul 21, 2020
@yannham yannham deleted the feature/improve-error-messages branch March 1, 2021 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant