Skip to content

Commit 5c442e1

Browse files
committed
Use Error type from Globals
1 parent 49b52a9 commit 5c442e1

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
data Exception :: !
1010

1111

12+
### Type Class Instances
13+
14+
instance showError :: Show Error
15+
16+
1217
### Values
1318

1419
catchException :: forall a eff. (Error -> Eff eff a) -> Eff (err :: Exception | eff) a -> Eff eff a
@@ -17,6 +22,6 @@
1722

1823
message :: Error -> String
1924

20-
stackTrace :: Error -> String
25+
showErrorImpl :: Error -> String
2126

2227
throwException :: forall a eff. Error -> Eff (err :: Exception | eff) a

src/Control/Monad/Eff/Exception.purs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@ import Control.Monad.Eff
55
foreign import data Exception :: !
66

77
foreign import data Error :: *
8-
9-
foreign import message
10-
"function message(e) {\
11-
\ return e.message;\
12-
\}" :: Error -> String
13-
14-
foreign import stackTrace
15-
"function stack(e) {\
16-
\ return e.stack;\
8+
9+
instance showError :: Show Error where
10+
show = showErrorImpl
11+
12+
foreign import showErrorImpl
13+
"function showErrorImpl(err) {\
14+
\ return err.stack ? err.stack : err.toString();\
1715
\}" :: Error -> String
1816

1917
foreign import error
2018
"function error(msg) {\
2119
\ return new Error(msg);\
22-
\}" :: String -> Error
20+
\};" :: String -> Error
2321

22+
foreign import message
23+
"function message(e) {\
24+
\ return e.message;\
25+
\}" :: Error -> String
26+
2427
foreign import throwException
2528
"function throwException(e) {\
2629
\ return function() {\

0 commit comments

Comments
 (0)