Code Monkey home page Code Monkey logo

purescript-exceptions's Introduction

PureScript

A small strongly typed programming language with expressive types that compiles to JavaScript, written in and inspired by Haskell.

Hackage Build Status

Language info

Resources

Help!

Community Spaces

The following spaces are governed by the PureScript Community Code of Conduct. The majority of PureScript users use these spaces to discuss and collaborate on PureScript-related topics:

Unaffiliated Spaces

Some PureScript users also collaborate in the below spaces. These do not fall under the code of conduct linked above. They may have no code of conduct or one very different than the one linked above.

purescript-exceptions's People

Contributors

davidchambers avatar garyb avatar hdgarrood avatar jedimahdi avatar joneshf avatar jordanmartinez avatar kedashoe avatar kl0tl avatar kritzcreek avatar ktorz avatar milesfrain avatar monoidmusician avatar natefaubion avatar nwolverson avatar paf31 avatar paluh avatar sigma-andex avatar tfausak avatar thomashoneyman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

purescript-exceptions's Issues

Add try operator

Could we add a try operator like Control.Exception has in Haskell? I'm currently using this:

try   a e. Eff (err  EXCEPTION | e) a  Eff e (Either Error a)
try action = catchException (pure ∘ Left) (Right <$> action)

The only problem would be that this introduces a dependency on purescript-either.

Add ability to specify Error.name

Currently, there is an accessor for Error.name (name :: Error -> String). It would be nice to have a helper that allows to create an error with a given name, like namedError :: String -> String -> Error.

Define Class for Convert PS ADT to and from Error

Sometime you need to differentiate Error thrown by your code, and catch only Error you want. The most common use case is when you want to throw Error in Aff, and catch it, but other code might don't want to catch all Error.

Possible Solution

Define a class SomeError or any good name for this purpose, usually these methods will be defined with help of FFI code. But we can provides utility functions here.

class Show e <= SomeError e where
  toError :: e -> Error
  fromError :: Error -> Maybe e

Rename "error"?

While working on purescript-batteries, I ran into a collision between Control.Monad.Eff.Exception.error and Control.Monad.Eff.Console.error. I think people are more likely to mean Console.error than Exception.error when they just say error.

I'm not sure what else I would call it, though. Maybe toError? Or perhaps there could be a throw :: String -> Eff (err :: EXCEPTION | e) a function, which would sidestep error and throwException.

Obviously this isn't a problem with this package per se. I could (and may) address this in purescript-batteries. But I wanted to open an issue here for discussion.

EXCEPTION row is named err

This means that types don't unify if you use Eff (exception :: EXCEPTION | e) a in your own type signature and use eg. throw.

Is there a reason for this, other than length? It seems inconsistent with every other effect row name.

catchException should not eliminate the effect

It is very misleading, and often a lie in the presence of asynchronicity. There are no clear semantics as to what it means to actually eliminate the effect (vs. purescript-run). I think it's better to just introduce the effect on both catchException and throwException. So you can't say "all exceptions are caught", you can only say "we are using the exception system provided by the host".

catchException catches all exceptions rather than just Error exceptions

It seems clear that this package is intended to catch Error exceptions. However, catchException does this:

try {
        return t();
      } catch (e) {
        if (e instanceof Error || Object.prototype.toString.call(e) === "[object Error]") {
          return c(e)();
        } else {
          return c(new Error(e.toString()))();
        }
}

That is, if the exception is determined to not be an Error exception, it attempts to convert the exception to an Error exception. This conversion itself throws for both null and undefined, which are possible values. Furthermore, this implementation prevents users from catching other types of exceptions in an obvious way (they would have to use a different catch before this one).

Suggestion: just rethrow the exception if it is not Error.

Add a `stack` accessor?

ie, stack :: Error -> String, that just reads the stack property. There's no agreed-upon format but according to MDN all modern browsers support it, and I'm pretty sure it's always a String.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.