Skip to content

Commit 49b52a9

Browse files
committed
Use opaque type for Error
1 parent 6789792 commit 49b52a9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### Types
66

7-
type Error = { stack :: String, message :: String }
7+
data Error :: *
88

99
data Exception :: !
1010

@@ -13,4 +13,10 @@
1313

1414
catchException :: forall a eff. (Error -> Eff eff a) -> Eff (err :: Exception | eff) a -> Eff eff a
1515

16+
error :: String -> Error
17+
18+
message :: Error -> String
19+
20+
stackTrace :: Error -> String
21+
1622
throwException :: forall a eff. Error -> Eff (err :: Exception | eff) a

src/Control/Monad/Eff/Exception.purs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@ import Control.Monad.Eff
44

55
foreign import data Exception :: !
66

7-
type Error = { message :: String, stack :: String }
7+
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;\
17+
\}" :: Error -> String
18+
19+
foreign import error
20+
"function error(msg) {\
21+
\ return new Error(msg);\
22+
\}" :: String -> Error
823

924
foreign import throwException
1025
"function throwException(e) {\

0 commit comments

Comments
 (0)