diff --git a/bower.json b/bower.json index 6dd2eb4..72b647d 100644 --- a/bower.json +++ b/bower.json @@ -13,6 +13,7 @@ }, "dependencies": { "purescript-arrays": "^4.0.1", + "purescript-exceptions": "matthewleon/purescript-exceptions#rethrow", "purescript-exists": "^3.0.0", "purescript-identity": "^3.0.0", "purescript-profunctor": "^3.0.0", @@ -20,11 +21,13 @@ "purescript-quickcheck": "^4.0.0", "purescript-transformers": "^3.1.0", "purescript-foldable-traversable": "^3.0.0", - "purescript-exceptions": "^3.0.0", "purescript-node-fs": "^4.0.0", "purescript-node-buffer": "^3.0.0", "purescript-node-readline": "^3.0.0", "purescript-datetime": "^3.0.0", "purescript-now": "^3.0.0" + }, + "resolutions": { + "purescript-exceptions": "rethrow" } } diff --git a/src/Benchotron/Core.js b/src/Benchotron/Core.js deleted file mode 100644 index 71e214c..0000000 --- a/src/Benchotron/Core.js +++ /dev/null @@ -1,19 +0,0 @@ -/* global exports */ -"use strict"; - -exports.handleBenchmarkException = function (name) { - return function (size) { - return function (innerAction) { - return function () { - try { - return innerAction(); - } catch(innerError) { - throw new Error( - 'While running Benchotron benchmark function: ' + name + ' ' + - 'at n=' + String(size) + ':\n' + - innerError.name + ': ' + innerError.message); - } - }; - }; - }; -}; diff --git a/src/Benchotron/Core.purs b/src/Benchotron/Core.purs index c6e9010..713feb5 100644 --- a/src/Benchotron/Core.purs +++ b/src/Benchotron/Core.purs @@ -28,7 +28,7 @@ import Control.Monad.State.Trans (StateT, evalStateT) import Control.Monad.State.Class (get, put) import Control.Monad.Trans.Class (lift) import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Exception (EXCEPTION) +import Control.Monad.Eff.Exception (EXCEPTION, rethrowException, error) import Control.Monad.Eff.Exception.Unsafe (unsafeThrow) import Control.Monad.Eff.Now (NOW) import Node.FS (FS) @@ -170,10 +170,12 @@ runBenchmarkF benchmark onChange = do where withIndices arr = zip (1..(length arr)) arr --- TODO: use purescript-exceptions instead. This appears to be blocked on: --- https://github.com/purescript/purescript-exceptions/issues/5 -foreign import handleBenchmarkException :: - forall e a. String -> Int -> Eff (BenchEffects e) a -> Eff (BenchEffects e) a +handleBenchmarkException :: forall e. String -> Int -> Eff (exception :: EXCEPTION | e) ~> Eff (exception :: EXCEPTION | e) +handleBenchmarkException name size = + rethrowException \innerError -> error $ + "While running Benchotron benchmark function: " <> name <> " " <> + "at n=" <> show size <> ":\n" <> + show innerError runBenchmarkFunction :: forall e a. Array a -> BenchmarkFunction a -> Eff (BenchEffects e) Stats runBenchmarkFunction inputs (BenchmarkFunction function') =