diff --git a/CHANGELOG.md b/CHANGELOG.md index 723dd9b..f16b013 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based Breaking changes: New features: +- Add `errorWithCause` (#43 by @sigma-andex) Bugfixes: diff --git a/src/Effect/Exception.js b/src/Effect/Exception.js index 40c0eee..7a55947 100644 --- a/src/Effect/Exception.js +++ b/src/Effect/Exception.js @@ -6,6 +6,12 @@ export function error(msg) { return new Error(msg); } +export function errorWithCause(msg) { + return function(cause) { + return new Error(msg, { cause }); + }; +} + export function message(e) { return e.message; } diff --git a/src/Effect/Exception.purs b/src/Effect/Exception.purs index 89e1668..fe4cf17 100644 --- a/src/Effect/Exception.purs +++ b/src/Effect/Exception.purs @@ -3,15 +3,17 @@ module Effect.Exception ( Error + , catchException , error + , errorWithCause , message , name , stack - , throwException - , catchException , throw + , throwException , try - ) where + ) + where import Prelude @@ -31,6 +33,9 @@ foreign import showErrorImpl :: Error -> String -- | Create a JavaScript error, specifying a message foreign import error :: String -> Error +-- | Create a JavaScript error, specifying a message and a cause +foreign import errorWithCause :: String -> Error -> Error + -- | Get the error message from a JavaScript error foreign import message :: Error -> String