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

Add API for exceptional error conditions #25

Merged
merged 2 commits into from
Nov 25, 2019
Merged

Add API for exceptional error conditions #25

merged 2 commits into from
Nov 25, 2019

Conversation

serras
Copy link
Collaborator

@serras serras commented Nov 25, 2019

Following a meeting with @kutyel and @pepegar, we have drafted an API for exceptional conditions in mu-haskell (errors like not found or not implemented).

  • We follow the design of both Servant and Mu, that is, and make the servers return ExceptT ServerError IO a instead of plain IO a as before.
  • To make simple server unaware of the extra ExceptT layer, there's an alwaysOk function which lifts a simple handler in IO to work on ExceptT ServerError IO.

This PR implements that API and updates the examples to use it.

Comments are welcome. The main paint points are:

  • Conduits also have to be upgraded to use those monad transformers (do they? maybe we can make them unaware of external errors, but this does not seam real...)
  • You have to sprinkle the alwaysOk here and there.

@serras serras requested a review from kutyel November 25, 2019 11:44
Copy link
Member

@pepegar pepegar left a comment

Choose a reason for hiding this comment

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

Just added a comment, apart of that, it looks awesome. Great job @serras !

core/rpc/src/Mu/Server.hs Outdated Show resolved Hide resolved
Copy link
Member

@kutyel kutyel left a comment

Choose a reason for hiding this comment

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

Looks good to me, awesome work! 🙌

todos <- liftIO $ readTVarIO t
case find (getMsg idMsg) todos of
Just todo -> pure $ TodoListResponse todo
Nothing -> serverError $ ServerError NotFound "unknown todolist id"
Copy link
Member

Choose a reason for hiding this comment

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

👀 This looks good, thanks for adding it! 👏

@serras serras merged commit 7674ef0 into master Nov 25, 2019
@serras serras deleted the errors branch November 25, 2019 13:12
kutyel pushed a commit that referenced this pull request Jan 4, 2022
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.

3 participants