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

Better evaluator errors #407

Merged
merged 1 commit into from
Jan 8, 2022
Merged

Better evaluator errors #407

merged 1 commit into from
Jan 8, 2022

Conversation

Martinsos
Copy link
Member

Same thing as for ParseError and for TypeError, but now for EvaluatorError -> I enriched errors with Ctx (source position) information and taught them how to display themselves and report ctx/position.

import Wasp.Analyzer.Type (Type)
import Wasp.Util (concatPrefixAndText, indent)

newtype EvaluationError = EvaluationError (WithCtx EvaluationError')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here for the first time I used WithCtx to put Ctx in the error, and not just AST. In the later PR I also do this for TypeError.

The only "ugly" thing is that I had a bit of hard time naming data EvaluationError'. I could name them EvaluationErrorWithCtx and EvaluationError, but the thing is that in the code we mostly use the first one and don't care about the second one much, so having such a long and overly detailed name sounded impractical. Therefore I decided to just call it EvaluationError and EvaluationError'. One other way to do it could be EvaluationError and EvaluationErrorReason/EvalautionErrorCause, but again I didn't want to over complicate.

Copy link
Contributor

@matijaSos matijaSos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! A few small comments

@@ -24,4 +24,4 @@ getErrorMessageAndCtx :: AnalyzeError -> (String, Ctx)
getErrorMessageAndCtx = \case
ParseError e -> first (("Parse error:\n" ++) . indent 2) $ PE.getErrorMessageAndCtx e
TypeError e -> first (("Type error:\n" ++) . indent 2) $ TE.getErrorMessageAndCtx e
EvaluationError _e -> error "TODO"
EvaluationError e -> first (("Evaluation error:\n" ++) . indent 2) $ EE.getErrorMessageAndCtx e
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How informative is it to the user to know that something is an "evaluation" error? Parse and Type error sound more intuitive (especially Type), but the evaluation is probably the least informative, right? I guess there is no other word that would make things clearer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, hard to say, but as you said, we don't have a better name right now. We could make it more general, just "Compiler error", but I am not sure if that brings any value also.

)
UndefinedVariable varName -> ("Undefined variable " ++ varName, ctx)
InvalidEnumVariant enumType validEnumVariants actualEnumVariant ->
( "Expected value of enum type '" ++ enumType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is awesome

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but when I finished it I realized this is one of those errors that will probably never happen due to typechecker doing most of the job and evaluations being generated automatically by our TH logic. But ok still cool :).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I considered doing something similar in earlier stages of compiler, but the thing is, if you type wrong identifier, e.g. AuthhMethod, it will fail during typechecking so early that TypeChecker doesn't yet know which type it expects there. We could probably make it work if we really wanted to, but I don't see an easy way right now to generate such nice error message for this case so I would rather leave that for later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just took a look, there is certainly a way to make this work, but it would require refactoring type inference to make it more intertwined with the type "weakening", and that would take some amount of time/focus to get right, so probably best not to do it now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, a lot of cool language words here :D But I agree that we don't have to go now into it if it is complicated. We could open a gh issue for it though, so we don't forget it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, created #421!

@Martinsos Martinsos force-pushed the better-type-errors branch 2 times, most recently from 8044623 to cf3ec4b Compare December 22, 2021 18:19
@Martinsos Martinsos force-pushed the better-evaluator-errors branch 2 times, most recently from 7e54f66 to b4f91ad Compare December 22, 2021 19:46
@shayneczyzewski
Copy link
Sponsor Contributor

LGTM 👍🏻 nice job!

Base automatically changed from better-type-errors to master January 8, 2022 22:50
@Martinsos Martinsos merged commit 7a0f75b into master Jan 8, 2022
@Martinsos Martinsos deleted the better-evaluator-errors branch January 8, 2022 22:52
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.

None yet

3 participants