Skip to content

Commit 1505b98

Browse files
committed
Merge pull request #12 from hdgarrood/stack
Add a `stack` accessor
2 parents fc2fbcd + da27bce commit 1505b98

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
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
}

docs/Control/Monad/Eff/Exception.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Module Control.Monad.Eff.Exception
22

33
This 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
1717
data 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
3030
error :: 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
3838
message :: 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

src/Control/Monad/Eff/Exception.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
1826
exports.throwException = function (e) {
1927
return function () {
2028
throw e;

src/Control/Monad/Eff/Exception.purs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,44 @@
11
-- | This module defines an effect, actions and handlers for working
2-
-- | with Javascript exceptions.
2+
-- | with JavaScript exceptions.
33

44
module Control.Monad.Eff.Exception
55
( EXCEPTION()
66
, Error()
77
, error
88
, message
9+
, stack
910
, throwException
1011
, catchException
1112
, throw
1213
) where
1314

1415
import Prelude
16+
import Data.Maybe (Maybe(..))
1517
import Control.Monad.Eff (Eff())
1618

1719
-- | This effect is used to annotate code which possibly throws exceptions
1820
foreign import data EXCEPTION :: !
1921

20-
-- | The type of Javascript errors
22+
-- | The type of JavaScript errors
2123
foreign import data Error :: *
2224

2325
instance showError :: Show Error where
2426
show = showErrorImpl
2527

2628
foreign import showErrorImpl :: Error -> String
2729

28-
-- | Create a Javascript error, specifying a message
30+
-- | Create a JavaScript error, specifying a message
2931
foreign import error :: String -> Error
3032

31-
-- | Get the error message from a Javascript error
33+
-- | Get the error message from a JavaScript error
3234
foreign 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:

0 commit comments

Comments
 (0)