File tree Expand file tree Collapse file tree 4 files changed +34
-9
lines changed Expand file tree Collapse file tree 4 files changed +34
-9
lines changed Original file line number Diff line number Diff line change 2020 " package.json"
2121 ],
2222 "dependencies" : {
23- "purescript-eff" : " ^0.1.2"
23+ "purescript-eff" : " ^0.1.2" ,
24+ "purescript-maybe" : " ^0.3.5"
2425 }
2526}
Original file line number Diff line number Diff line change 11## Module Control.Monad.Eff.Exception
22
33This module defines an effect, actions and handlers for working
4- with Javascript exceptions.
4+ with JavaScript exceptions.
55
66#### ` EXCEPTION `
77
@@ -17,7 +17,7 @@ This effect is used to annotate code which possibly throws exceptions
1717data Error :: *
1818```
1919
20- The type of Javascript errors
20+ The type of JavaScript errors
2121
2222##### Instances
2323``` purescript
@@ -30,15 +30,23 @@ Show Error
3030error :: String -> Error
3131```
3232
33- Create a Javascript error, specifying a message
33+ Create a JavaScript error, specifying a message
3434
3535#### ` message `
3636
3737``` purescript
3838message :: Error -> String
3939```
4040
41- Get the error message from a Javascript error
41+ Get the error message from a JavaScript error
42+
43+ #### ` stack `
44+
45+ ``` purescript
46+ stack :: Error -> Maybe String
47+ ```
48+
49+ Get the stack trace from a JavaScript error
4250
4351#### ` throwException `
4452
Original file line number Diff line number Diff line change @@ -15,6 +15,14 @@ exports.message = function (e) {
1515 return e . message ;
1616} ;
1717
18+ exports . stackImpl = function ( just ) {
19+ return function ( nothing ) {
20+ return function ( e ) {
21+ return e . stack ? just ( e . stack ) : nothing ;
22+ } ;
23+ } ;
24+ } ;
25+
1826exports . throwException = function ( e ) {
1927 return function ( ) {
2028 throw e ;
Original file line number Diff line number Diff line change 11-- | This module defines an effect, actions and handlers for working
2- -- | with Javascript exceptions.
2+ -- | with JavaScript exceptions.
33
44module Control.Monad.Eff.Exception
55 ( EXCEPTION ()
66 , Error ()
77 , error
88 , message
9+ , stack
910 , throwException
1011 , catchException
1112 , throw
1213 ) where
1314
1415import Prelude
16+ import Data.Maybe (Maybe (..))
1517import Control.Monad.Eff (Eff ())
1618
1719-- | This effect is used to annotate code which possibly throws exceptions
1820foreign import data EXCEPTION :: !
1921
20- -- | The type of Javascript errors
22+ -- | The type of JavaScript errors
2123foreign import data Error :: *
2224
2325instance showError :: Show Error where
2426 show = showErrorImpl
2527
2628foreign import showErrorImpl :: Error -> String
2729
28- -- | Create a Javascript error, specifying a message
30+ -- | Create a JavaScript error, specifying a message
2931foreign import error :: String -> Error
3032
31- -- | Get the error message from a Javascript error
33+ -- | Get the error message from a JavaScript error
3234foreign import message :: Error -> String
3335
36+ -- | Get the stack trace from a JavaScript error
37+ stack :: Error -> Maybe String
38+ stack = stackImpl Just Nothing
39+
40+ foreign import stackImpl :: (forall a . a -> Maybe a ) -> (forall a . Maybe a ) -> Error -> Maybe String
41+
3442-- | Throw an exception
3543-- |
3644-- | For example:
You can’t perform that action at this time.
0 commit comments