diff --git a/.eslintrc.json b/.eslintrc.json index 84cef4f..1c6afb9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,11 +1,9 @@ { "parserOptions": { - "ecmaVersion": 5 + "ecmaVersion": 6, + "sourceType": "module" }, "extends": "eslint:recommended", - "env": { - "commonjs": true - }, "rules": { "strict": [2, "global"], "block-scoped-var": 2, diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..4435abb --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,12 @@ +**Description of the change** + +Clearly and concisely describe the purpose of the pull request. If this PR relates to an existing issue or change proposal, please link to it. Include any other background context that would help reviewers understand the motivation for this PR. + +--- + +**Checklist:** + +- [ ] Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)") +- [ ] Linked any existing issues or proposals that this pull request should close +- [ ] Updated or added relevant documentation +- [ ] Added a test for the contribution (if applicable) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2972ba..c69237a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,10 @@ name: CI -on: push +on: + push: + branches: [master] + pull_request: + branches: [master] jobs: build: @@ -10,11 +14,11 @@ jobs: - uses: purescript-contrib/setup-purescript@main with: - purescript: "0.14.0-rc3" + purescript: "unstable" - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: - node-version: "12" + node-version: "14.x" - name: Install dependencies run: | diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..03b5b86 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,117 @@ +# Changelog + +Notable changes to this project are documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +Breaking changes: + +New features: + +Bugfixes: + +Other improvements: + +## [v6.1.0](https://github.com/purescript/purescript-exceptions/releases/tag/v6.1.0) - 2024-06-30 + +New features: +- Add `errorWithCause` (#43 by @sigma-andex) +- Add `errorWithName` (#44 by @jedimahdi) + +## [v6.0.0](https://github.com/purescript/purescript-exceptions/releases/tag/v6.0.0) - 2022-04-27 + +Breaking changes: +- Migrate FFI to ES modules (#41 by @JordanMartinez) + +New features: + +Bugfixes: + +Other improvements: + +## [v5.0.0](https://github.com/purescript/purescript-exceptions/releases/tag/v5.0.0) - 2021-02-26 + +Breaking changes: +- Added support for PureScript 0.14 and dropped support for all previous versions (#36) + +New features: + +Bugfixes: +- Fixed `catchException` example to use `Console.logShow` instead of `print` (#31) + +Other improvements: +- Migrated CI to GitHub Actions and updated installation instructions to use Spago (#37) +- Added a CHANGELOG.md file and pull request template (#38, #39) +- Removed unnecessary type variable from `try` docstring (#33) + +## [v4.0.0](https://github.com/purescript/purescript-exceptions/releases/tag/v4.0.0) - 2018-05-23 + +Updated for PureScript 0.12 + +## [v3.1.0](https://github.com/purescript/purescript-exceptions/releases/tag/v3.1.0) - 2017-07-27 + +Add `name` function to extract the name of an `Error` (@KtorZ) + +## [v3.0.0](https://github.com/purescript/purescript-exceptions/releases/tag/v3.0.0) - 2017-03-26 + +- Updated for PureScript 0.11 +- The `err :: EXCEPTION` row entry has been corrected to `exception :: EXCEPTION` + +## [v2.0.0](https://github.com/purescript/purescript-exceptions/releases/tag/v2.0.0) - 2016-10-07 + +- Updated dependencies + +## [v1.0.0](https://github.com/purescript/purescript-exceptions/releases/tag/v1.0.0) - 2016-06-01 + +This release is intended for the PureScript 0.9.1 compiler and newer. + +**Note**: The v1.0.0 tag is not meant to indicate the library is “finished”, the core libraries are all being bumped to this for the 0.9 compiler release so as to use semver more correctly. + +## [v1.0.0-rc.1](https://github.com/purescript/purescript-exceptions/releases/tag/v1.0.0-rc.1) - 2016-03-16 + +- Release candidate for the psc 0.8+ core libraries + +## [v0.3.4](https://github.com/purescript/purescript-exceptions/releases/tag/v0.3.4) - 2015-12-23 + +- Add `stack` error message accessor (@hdgarrood) + +## [v0.3.3](https://github.com/purescript/purescript-exceptions/releases/tag/v0.3.3) - 2015-12-11 + +Add `throw` (@hdgarrood) + +## [v0.3.2](https://github.com/purescript/purescript-exceptions/releases/tag/v0.3.2) - 2015-11-20 + +- Removed unused import (@tfausak) + +## [v0.3.1](https://github.com/purescript/purescript-exceptions/releases/tag/v0.3.1) - 2015-11-13 + +Added `Unsafe` module (@hdgarrood) + +## [v0.3.0](https://github.com/purescript/purescript-exceptions/releases/tag/v0.3.0) - 2015-06-30 + +This release works with versions 0.7.\* of the PureScript compiler. It will not work with older versions. If you are using an older version, you should require an older, compatible version of this library. + +## [v0.3.0-rc.1](https://github.com/purescript/purescript-exceptions/releases/tag/v0.3.0-rc.1) - 2015-06-09 + +Initial release candidate of the library intended for the 0.7 compiler. + +## [v0.2.3](https://github.com/purescript/purescript-exceptions/releases/tag/v0.2.3) - 2015-03-20 + +Updated docs + +## [v0.2.2](https://github.com/purescript/purescript-exceptions/releases/tag/v0.2.2) - 2014-11-16 + +Improvements to FFI code (@davidchambers) + +## [v0.2.1](https://github.com/purescript/purescript-exceptions/releases/tag/v0.2.1) - 2014-09-04 + +Handle errors from other JS domains (@joneshf) + +## [v0.2.0](https://github.com/purescript/purescript-exceptions/releases/tag/v0.2.0) - 2014-08-07 + + + +## [v0.1.0](https://github.com/purescript/purescript-exceptions/releases/tag/v0.1.0) - 2014-04-25 + + + diff --git a/README.md b/README.md index 4eeea8c..4a07e97 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ [![Latest release](http://img.shields.io/github/release/purescript/purescript-exceptions.svg)](https://github.com/purescript/purescript-exceptions/releases) [![Build status](https://github.com/purescript/purescript-exceptions/workflows/CI/badge.svg?branch=master)](https://github.com/purescript/purescript-exceptions/actions?query=workflow%3ACI+branch%3Amaster) +[![Pursuit](https://pursuit.purescript.org/packages/purescript-exceptions/badge)](https://pursuit.purescript.org/packages/purescript-exceptions) Exception effects. diff --git a/bower.json b/bower.json index c7bd741..ab0b012 100644 --- a/bower.json +++ b/bower.json @@ -4,7 +4,7 @@ "license": "BSD-3-Clause", "repository": { "type": "git", - "url": "git://github.com/purescript/purescript-exceptions.git" + "url": "https://github.com/purescript/purescript-exceptions.git" }, "ignore": [ "**/.*", @@ -16,9 +16,9 @@ "package.json" ], "dependencies": { - "purescript-effect": "master", - "purescript-either": "master", - "purescript-maybe": "master", - "purescript-prelude": "master" + "purescript-effect": "^4.0.0", + "purescript-either": "^6.0.0", + "purescript-maybe": "^6.0.0", + "purescript-prelude": "^6.0.0" } } diff --git a/package.json b/package.json index 9452364..4ea39f9 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "build": "eslint src && pulp build -- --censor-lib --strict" }, "devDependencies": { - "eslint": "^4.19.1", - "pulp": "^15.0.0", - "purescript-psa": "^0.8.0", - "rimraf": "^2.6.2" + "eslint": "^7.15.0", + "pulp": "16.0.0-0", + "purescript-psa": "^0.8.2", + "rimraf": "^3.0.2" } } diff --git a/src/Effect/Exception.js b/src/Effect/Exception.js index a5aa8c4..5e7b9d9 100644 --- a/src/Effect/Exception.js +++ b/src/Effect/Exception.js @@ -1,36 +1,48 @@ -"use strict"; - -exports.showErrorImpl = function (err) { +export function showErrorImpl(err) { return err.stack || err.toString(); -}; +} -exports.error = function (msg) { +export function error(msg) { return new Error(msg); -}; +} + +export function errorWithCause(msg) { + return function(cause) { + return new Error(msg, { cause }); + }; +} + +export function errorWithName(msg) { + return function(name) { + const e = new Error(msg); + e.name = name; + return e; + }; +} -exports.message = function (e) { +export function message(e) { return e.message; -}; +} -exports.name = function (e) { +export function name(e) { return e.name || "Error"; -}; +} -exports.stackImpl = function (just) { +export function stackImpl(just) { return function (nothing) { return function (e) { return e.stack ? just(e.stack) : nothing; }; }; -}; +} -exports.throwException = function (e) { +export function throwException(e) { return function () { throw e; }; -}; +} -exports.catchException = function (c) { +export function catchException(c) { return function (t) { return function () { try { @@ -44,4 +56,4 @@ exports.catchException = function (c) { } }; }; -}; +} diff --git a/src/Effect/Exception.purs b/src/Effect/Exception.purs index 89e1668..f4c1beb 100644 --- a/src/Effect/Exception.purs +++ b/src/Effect/Exception.purs @@ -3,15 +3,18 @@ module Effect.Exception ( Error + , catchException , error + , errorWithCause + , errorWithName , message , name , stack - , throwException - , catchException , throw + , throwException , try - ) where + ) + where import Prelude @@ -31,6 +34,12 @@ 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 + +-- | 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