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 handling #4

Merged
merged 8 commits into from
Aug 20, 2016
Merged

Improve error handling #4

merged 8 commits into from
Aug 20, 2016

Conversation

mheinzel
Copy link
Contributor

@mheinzel mheinzel commented Aug 6, 2016

Previously, in some places error and exitFailure were used to handle errors, so the whole program terminated.
Now the parsing uses Either (which was much simpler than I thought) and in case of an uncaught exception, the continuation is aborted.

To obtain the terminating continuation, we have to use callCC inside the Interpreter monad, which means it can no be set in the initial state. I'm not really happy with that solution, but can't think of anything more elegant at the moment.

The nice thing is, the REPL now doesn't close itself when encountering a parsing error or uncaught exception. It just ignores the current line, like the regular Python REPL.

This is the first time I'm working with monad transformer stacks, so it takes some time to grasp all the details, but it's fun and I already learned a lot. I want to do 1 or 2 more small fixes, then I am going to tackle generators.

Matthias

@mheinzel
Copy link
Contributor Author

mheinzel commented Aug 9, 2016

Put this one on hold for a moment, please. There's still something I need to check.

@mheinzel
Copy link
Contributor Author

Okay, parsing errors now result in a non-zero exit code, but for uncaught exceptions it is a bit harder to do (without calling exitFailure in the handler).

Currently, encountering the default exception handler terminates execution of the continuation, but to recognize it terminated early, we'd need to add a stateFailed flag to InterpreterState or introduce something like ExceptT to the tranformer stack.

Any thoughts?

@mheinzel
Copy link
Contributor Author

Now it works out. In case of an uncaught exception, name and text are written to stateErrorMsg, the continuation is used to terminate execution and runInterpreter returns Left (stateErrorMsg newState).

@mattgreen
Copy link
Owner

Looks good, thanks!

@mattgreen mattgreen merged commit 354a2be into mattgreen:master Aug 20, 2016
@mheinzel mheinzel deleted the errorhandling branch September 29, 2016 18:17
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.

2 participants