Skip to content

Update for PureScript 0.12 #29

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

Merged
merged 4 commits into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/bower_components/
/node_modules/
/output/
package-lock.json
38 changes: 22 additions & 16 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
The MIT License (MIT)
Copyright 2018 PureScript

Copyright (c) 2014 PureScript
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10 changes: 5 additions & 5 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "purescript-exceptions",
"homepage": "https://github.com/purescript/purescript-exceptions",
"description": "Exception effects",
"license": "MIT",
"license": "BSD-3-Clause",
"repository": {
"type": "git",
"url": "git://github.com/purescript/purescript-exceptions.git"
Expand All @@ -17,8 +16,9 @@
"package.json"
],
"dependencies": {
"purescript-eff": "^3.0.0",
"purescript-either": "^3.0.0",
"purescript-maybe": "^3.0.0"
"purescript-effect": "^2.0.0",
"purescript-either": "^4.0.0",
"purescript-maybe": "^4.0.0",
"purescript-prelude": "^4.0.0"
}
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"build": "eslint src && pulp build -- --censor-lib --strict"
},
"devDependencies": {
"eslint": "^3.17.1",
"pulp": "^10.0.4",
"purescript-psa": "^0.5.0-rc.1",
"rimraf": "^2.6.1"
"eslint": "^4.19.1",
"pulp": "^12.2.0",
"purescript-psa": "^0.6.0",
"rimraf": "^2.6.2"
}
}
File renamed without changes.
31 changes: 12 additions & 19 deletions src/Control/Monad/Eff/Exception.purs → src/Effect/Exception.purs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
-- | This module defines an effect, actions and handlers for working
-- | with JavaScript exceptions.

module Control.Monad.Eff.Exception
( EXCEPTION
, Error
module Effect.Exception
( Error
, error
, message
, name
Expand All @@ -16,14 +15,11 @@ module Control.Monad.Eff.Exception

import Prelude

import Control.Monad.Eff (Eff, kind Effect)
import Effect (Effect)

import Data.Either (Either(..))
import Data.Maybe (Maybe(..))

-- | This effect is used to annotate code which possibly throws exceptions
foreign import data EXCEPTION :: Effect

-- | The type of JavaScript errors
foreign import data Error :: Type

Expand Down Expand Up @@ -62,29 +58,27 @@ foreign import stackImpl
-- | error "Expected a non-negative number"
-- | ```
foreign import throwException
:: forall a eff
:: forall a
. Error
-> Eff (exception :: EXCEPTION | eff) a
-> Effect a

-- | Catch an exception by providing an exception handler.
-- |
-- | This handler removes the `EXCEPTION` effect.
-- |
-- | For example:
-- |
-- | ```purescript
-- | main = catchException print do
-- | Console.log "Exceptions thrown in this block will be logged to the console"
-- | ```
foreign import catchException
:: forall a eff
. (Error -> Eff eff a)
-> Eff (exception :: EXCEPTION | eff) a
-> Eff eff a
:: forall a
. (Error -> Effect a)
-> Effect a
-> Effect a

-- | A shortcut allowing you to throw an error in one step. Defined as
-- | `throwException <<< error`.
throw :: forall eff a. String -> Eff (exception :: EXCEPTION | eff) a
throw :: forall a. String -> Effect a
throw = throwException <<< error

-- | Runs an Eff and returns eventual Exceptions as a `Left` value. If the
Expand All @@ -93,8 +87,7 @@ throw = throwException <<< error
-- | For example:
-- |
-- | ```purescript
-- | -- Notice that there is no EXCEPTION effect
-- | main :: forall eff. Eff (console :: CONSOLE, fs :: FS | eff) Unit
-- | main :: forall eff. Effect Unit
-- | main = do
-- | result <- try (readTextFile UTF8 "README.md")
-- | case result of
Expand All @@ -104,5 +97,5 @@ throw = throwException <<< error
-- | Console.error ("Couldn't open README.md. Error was: " <> show error)
-- | ```

try :: forall eff a. Eff (exception :: EXCEPTION | eff) a -> Eff eff (Either Error a)
try :: forall a. Effect a -> Effect (Either Error a)
try action = catchException (pure <<< Left) (Right <$> action)
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module Control.Monad.Eff.Exception.Unsafe where
module Effect.Exception.Unsafe where

import Control.Monad.Eff.Exception (Error, error, throwException)
import Control.Monad.Eff.Unsafe (unsafePerformEff)
import Effect.Exception (Error, error, throwException)
import Effect.Unsafe (unsafePerformEffect)
import Control.Semigroupoid ((<<<))

-- | Throw an exception in pure code. This function should be used very
-- | sparingly, as it can cause unexpected crashes at runtime.
unsafeThrowException :: forall a. Error -> a
unsafeThrowException = unsafePerformEff <<< throwException
unsafeThrowException = unsafePerformEffect <<< throwException

-- | Defined as `unsafeThrowException <<< error`.
unsafeThrow :: forall a. String -> a
Expand Down