From 352928296e596d084a320dad00da49c6fd33bf95 Mon Sep 17 00:00:00 2001 From: Gary Burgess Date: Sun, 24 Jan 2016 16:02:17 +0000 Subject: [PATCH] Updates for PureScript 0.8 --- .jscsrc | 5 ++ .jshintrc | 5 +- .travis.yml | 16 +++- README.md | 4 +- bower.json | 7 +- docs/Control/Monad/Eff/Exception.md | 94 --------------------- docs/Control/Monad/Eff/Exception/Unsafe.md | 20 ----- package.json | 13 +-- src/Control/Monad/Eff/Exception.purs | 27 ++++-- src/Control/Monad/Eff/Exception/Unsafe.purs | 6 +- 10 files changed, 55 insertions(+), 142 deletions(-) delete mode 100644 docs/Control/Monad/Eff/Exception.md delete mode 100644 docs/Control/Monad/Eff/Exception/Unsafe.md diff --git a/.jscsrc b/.jscsrc index 342da66..2561ce9 100644 --- a/.jscsrc +++ b/.jscsrc @@ -1,5 +1,10 @@ { "preset": "grunt", + "disallowSpacesInFunctionExpression": null, + "requireSpacesInFunctionExpression": { + "beforeOpeningRoundBrace": true, + "beforeOpeningCurlyBrace": true + }, "disallowSpacesInAnonymousFunctionExpression": null, "requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, diff --git a/.jshintrc b/.jshintrc index f391159..620d8d7 100644 --- a/.jshintrc +++ b/.jshintrc @@ -5,7 +5,7 @@ "freeze": true, "funcscope": true, "futurehostile": true, - "globalstrict": true, + "strict": "global", "latedef": true, "maxparams": 1, "noarg": true, @@ -15,5 +15,6 @@ "singleGroups": true, "undef": true, "unused": true, - "eqnull": true + "eqnull": true, + "predef": ["exports"] } diff --git a/.travis.yml b/.travis.yml index 791313a..36183ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js -sudo: false -node_js: - - 0.10 +sudo: required +dist: trusty +node_js: 5 env: - PATH=$HOME/purescript:$PATH install: @@ -9,6 +9,16 @@ install: - wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz - tar -xvf $HOME/purescript.tar.gz -C $HOME/ - chmod a+x $HOME/purescript + - npm install -g bower - npm install + - bower install script: - npm run build +after_success: +- >- + test $TRAVIS_TAG && + psc-publish > .pursuit.json && + curl -X POST http://pursuit.purescript.org/packages \ + -d @.pursuit.json \ + -H 'Accept: application/json' \ + -H "Authorization: token ${GITHUB_TOKEN}" diff --git a/README.md b/README.md index 4bba301..a32883e 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,6 @@ Exception effects. bower install purescript-exceptions ``` -## Module documentation +## Documentation -- [Control.Monad.Eff.Exception](docs/Control/Monad/Eff/Exception.md) +Module documentation is [published on Pursuit](http://pursuit.purescript.org/packages/purescript-exceptions). diff --git a/bower.json b/bower.json index 172a563..88595f5 100644 --- a/bower.json +++ b/bower.json @@ -2,9 +2,6 @@ "name": "purescript-exceptions", "homepage": "https://github.com/purescript/purescript-exceptions", "description": "Exception effects", - "keywords": [ - "purescript" - ], "license": "MIT", "repository": { "type": "git", @@ -20,7 +17,7 @@ "package.json" ], "dependencies": { - "purescript-eff": "^0.1.2", - "purescript-maybe": "^0.3.5" + "purescript-eff": "^1.0.0-rc.1", + "purescript-maybe": "^1.0.0-rc.1" } } diff --git a/docs/Control/Monad/Eff/Exception.md b/docs/Control/Monad/Eff/Exception.md deleted file mode 100644 index 75c2f95..0000000 --- a/docs/Control/Monad/Eff/Exception.md +++ /dev/null @@ -1,94 +0,0 @@ -## Module Control.Monad.Eff.Exception - -This module defines an effect, actions and handlers for working -with JavaScript exceptions. - -#### `EXCEPTION` - -``` purescript -data EXCEPTION :: ! -``` - -This effect is used to annotate code which possibly throws exceptions - -#### `Error` - -``` purescript -data Error :: * -``` - -The type of JavaScript errors - -##### Instances -``` purescript -Show Error -``` - -#### `error` - -``` purescript -error :: String -> Error -``` - -Create a JavaScript error, specifying a message - -#### `message` - -``` purescript -message :: Error -> String -``` - -Get the error message from a JavaScript error - -#### `stack` - -``` purescript -stack :: Error -> Maybe String -``` - -Get the stack trace from a JavaScript error - -#### `throwException` - -``` purescript -throwException :: forall a eff. Error -> Eff (err :: EXCEPTION | eff) a -``` - -Throw an exception - -For example: - -```purescript -main = do - x <- readNumber - when (x < 0) $ throwException $ - error "Expected a non-negative number" -``` - -#### `catchException` - -``` purescript -catchException :: forall a eff. (Error -> Eff eff a) -> Eff (err :: EXCEPTION | eff) a -> Eff eff a -``` - -Catch an exception by providing an exception handler. - -This handler removes the `EXCEPTION` effect. - -For example: - -```purescript -main = catchException print do - trace "Exceptions thrown in this block will be logged to the console" -``` - -#### `throw` - -``` purescript -throw :: forall eff a. String -> Eff (err :: EXCEPTION | eff) a -``` - -A shortcut allowing you to throw an error in one step. Defined as -`throwException <<< error`. - - diff --git a/docs/Control/Monad/Eff/Exception/Unsafe.md b/docs/Control/Monad/Eff/Exception/Unsafe.md deleted file mode 100644 index 4897e61..0000000 --- a/docs/Control/Monad/Eff/Exception/Unsafe.md +++ /dev/null @@ -1,20 +0,0 @@ -## Module Control.Monad.Eff.Exception.Unsafe - -#### `unsafeThrowException` - -``` purescript -unsafeThrowException :: forall a. Error -> a -``` - -Throw an exception in pure code. This function should be used very -sparingly, as it can cause unexpected crashes at runtime. - -#### `unsafeThrow` - -``` purescript -unsafeThrow :: forall a. String -> a -``` - -Defined as `unsafeThrowException <<< error`. - - diff --git a/package.json b/package.json index e129c49..55fc1c7 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "private": true, "scripts": { - "postinstall": "pulp dep install", - "build": "jshint src && jscs src && pulp build && rimraf docs && pulp docs" + "clean": "rimraf output && rimraf .pulp-cache", + "build": "jshint src && jscs src && pulp build", + "test": "jshint src && jscs src && pulp test" }, "devDependencies": { - "jscs": "^1.13.1", - "jshint": "^2.8.0", - "pulp": "^4.0.2", - "rimraf": "^2.4.1" + "jscs": "^2.8.0", + "jshint": "^2.9.1", + "pulp": "^8.1.0", + "rimraf": "^2.5.0" } } diff --git a/src/Control/Monad/Eff/Exception.purs b/src/Control/Monad/Eff/Exception.purs index 989115c..a3b4660 100644 --- a/src/Control/Monad/Eff/Exception.purs +++ b/src/Control/Monad/Eff/Exception.purs @@ -2,8 +2,8 @@ -- | with JavaScript exceptions. module Control.Monad.Eff.Exception - ( EXCEPTION() - , Error() + ( EXCEPTION + , Error , error , message , stack @@ -12,9 +12,11 @@ module Control.Monad.Eff.Exception , throw ) where -import Prelude +import Control.Monad.Eff (Eff) +import Control.Semigroupoid ((<<<)) + import Data.Maybe (Maybe(..)) -import Control.Monad.Eff (Eff()) +import Data.Show (class Show) -- | This effect is used to annotate code which possibly throws exceptions foreign import data EXCEPTION :: ! @@ -37,7 +39,11 @@ foreign import message :: Error -> String stack :: Error -> Maybe String stack = stackImpl Just Nothing -foreign import stackImpl :: (forall a. a -> Maybe a) -> (forall a. Maybe a) -> Error -> Maybe String +foreign import stackImpl + :: (forall a. a -> Maybe a) + -> (forall a. Maybe a) + -> Error + -> Maybe String -- | Throw an exception -- | @@ -49,7 +55,10 @@ foreign import stackImpl :: (forall a. a -> Maybe a) -> (forall a. Maybe a) -> E -- | when (x < 0) $ throwException $ -- | error "Expected a non-negative number" -- | ``` -foreign import throwException :: forall a eff. Error -> Eff (err :: EXCEPTION | eff) a +foreign import throwException + :: forall a eff + . Error + -> Eff (err :: EXCEPTION | eff) a -- | Catch an exception by providing an exception handler. -- | @@ -61,7 +70,11 @@ foreign import throwException :: forall a eff. Error -> Eff (err :: EXCEPTION | -- | main = catchException print do -- | trace "Exceptions thrown in this block will be logged to the console" -- | ``` -foreign import catchException :: forall a eff. (Error -> Eff eff a) -> Eff (err :: EXCEPTION | eff) a -> Eff eff a +foreign import catchException + :: forall a eff + . (Error -> Eff eff a) + -> Eff (err :: EXCEPTION | eff) a + -> Eff eff a -- | A shortcut allowing you to throw an error in one step. Defined as -- | `throwException <<< error`. diff --git a/src/Control/Monad/Eff/Exception/Unsafe.purs b/src/Control/Monad/Eff/Exception/Unsafe.purs index 5a83bdb..64fec7c 100644 --- a/src/Control/Monad/Eff/Exception/Unsafe.purs +++ b/src/Control/Monad/Eff/Exception/Unsafe.purs @@ -1,8 +1,8 @@ module Control.Monad.Eff.Exception.Unsafe where -import Prelude -import Control.Monad.Eff.Unsafe -import Control.Monad.Eff.Exception +import Control.Monad.Eff.Exception (Error, error, throwException) +import Control.Monad.Eff.Unsafe (unsafePerformEff) +import Control.Semigroupoid ((<<<)) -- | Throw an exception in pure code. This function should be used very -- | sparingly, as it can cause unexpected crashes at runtime.