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

Possibly implement a funtion to exit for PsuedoExceptions #21

Open
bbarker opened this issue Dec 17, 2020 · 3 comments
Open

Possibly implement a funtion to exit for PsuedoExceptions #21

bbarker opened this issue Dec 17, 2020 · 3 comments

Comments

@bbarker
Copy link

bbarker commented Dec 17, 2020

I recently had (possibly good) cause to have a function like this:

    seOrExit ::  SX.SomeException -> SomeNonPseudoException
    seOrExit e = case SX.fromException e of
      Just se -> se
      Nothing ->
        unsafePerformIO $ SE.die  "Received a PseudoException, exiting! "

The context is that I can use seOrExit with a mapError that works on my monad transformer stack that is built on top of UIO.
If you're chugging along, and get a psuedo exception, I'm not sure what else there is to be done about it anyway, other than performing an alternative form of logging.

Anyway, wanted to get your thoughts on this use case. Maybe this is terrible.

@singpolyma
Copy link
Owner

singpolyma commented Dec 17, 2020

If you use unexceptionalid functions to build a stack based on UIO I'm curious how you end up with a SomeException at all? Should always end up with at most a SomeNonPseudoException because PseudoException should not be caught in UIO context.

@bbarker
Copy link
Author

bbarker commented Dec 17, 2020

Perhaps I went wrong somewhere, but here's what I did:

  xsd <- liftEither $ parseText def $ TL.fromStrict xsdTxt

Due to parseText (being a function from a 3rd party library) possibly returning Left SomeException as part of it's signature, I then needed a function like mapZErrorOrExit :: ZIO r SX.SomeException a -> ZIO r SomeNonPseudoException a to absolve the error as in:

  xsd <- mapZErrorOrExit $ liftEither $ parseText def $ TL.fromStrict xsdTxt

I can imagine other alternatives, though I haven't really imagined any obviously better alternatives so far.

@singpolyma
Copy link
Owner

Oh interesting. That's a case I guess I hadn't considered: when a library already catches/returns exceptions but doesn't use anything more specific than SomeException.

Here's an option:

xsd <- UIO.fromIO $ UIO.runEitherIO $ return $ parseText def $ TL.fromStrict xsdTxt

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

No branches or pull requests

2 participants