Skip to content

Commit

Permalink
Add errorWithName constructor (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
jedimahdi authored Jun 30, 2024
1 parent e110d79 commit 57220fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Breaking changes:

New features:
- Add `errorWithCause` (#43 by @sigma-andex)
- Add `errorWithName` (#44 by @jedimahdi)

Bugfixes:

Expand Down
8 changes: 8 additions & 0 deletions src/Effect/Exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export function errorWithCause(msg) {
};
}

export function errorWithName(msg) {
return function(name) {
const e = new Error(msg);
e.name = name;
return e;
};
}

export function message(e) {
return e.message;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Effect/Exception.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Effect.Exception
, catchException
, error
, errorWithCause
, errorWithName
, message
, name
, stack
Expand Down Expand Up @@ -36,6 +37,9 @@ foreign import error :: String -> Error
-- | Create a JavaScript error, specifying a message and a cause
foreign import errorWithCause :: String -> Error -> Error

-- | Create a JavaScript error, specifying a message and a name
foreign import errorWithName :: String -> String -> Error

-- | Get the error message from a JavaScript error
foreign import message :: Error -> String

Expand Down

0 comments on commit 57220fa

Please sign in to comment.