Skip to content

Commit e110d79

Browse files
authored
Add errorWithCause constructor (#43)
* Add errorWithCause constructor * Update changelog
1 parent afab3c0 commit e110d79

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88

99
New features:
10+
- Add `errorWithCause` (#43 by @sigma-andex)
1011

1112
Bugfixes:
1213

src/Effect/Exception.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export function error(msg) {
66
return new Error(msg);
77
}
88

9+
export function errorWithCause(msg) {
10+
return function(cause) {
11+
return new Error(msg, { cause });
12+
};
13+
}
14+
915
export function message(e) {
1016
return e.message;
1117
}

src/Effect/Exception.purs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@
33

44
module Effect.Exception
55
( Error
6+
, catchException
67
, error
8+
, errorWithCause
79
, message
810
, name
911
, stack
10-
, throwException
11-
, catchException
1212
, throw
13+
, throwException
1314
, try
14-
) where
15+
)
16+
where
1517

1618
import Prelude
1719

@@ -31,6 +33,9 @@ foreign import showErrorImpl :: Error -> String
3133
-- | Create a JavaScript error, specifying a message
3234
foreign import error :: String -> Error
3335

36+
-- | Create a JavaScript error, specifying a message and a cause
37+
foreign import errorWithCause :: String -> Error -> Error
38+
3439
-- | Get the error message from a JavaScript error
3540
foreign import message :: Error -> String
3641

0 commit comments

Comments
 (0)