-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored the error handling (#474)
* Refactored the error handling This commit reimplements the error handling of encorec. Before, an error carried the message that should be displayed, meaning that the more detailed a message you wanted, the more bloated the error handling code got. The new model introduces a datatype `Error` which has one constructor for each kind of error, and showing this value prints the error message. For example, if there is a type mismatch error, instead of writing ``` tcError $ "Expected type '" ++ show ty1 ++ "' but found '" ++ show ty2 ++ "'" ``` you now write ``` tcError $ TypeMismatchError ty1 ty2 ``` The hope is that this will encourage writing better error messages, and also that it will reduce code duplication when the same kind of error message needs to be thrown by two different places in the code. As an added bonus, we can now catch specific errors: ``` matchTypes (getResultType expected) (getResultType ty) `catchError` (\case TCError (TypeMismatchError _ _) _ -> tcError $ TypeMismatchError ty expected TCError err _ -> tcError err ) ``` If the first line above throws a `TypeMismatchError`, we will catch it and throw a new error. If it's another error we will pass this error along. * Reacting to Kiko's comments This commit can be squashed after review!
- Loading branch information
Showing
7 changed files
with
442 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.