fix: catch execution context errors, pedantic packages
This commit is contained in:
parent
540ffb2f78
commit
1a2c4828fd
30
spago.yaml
30
spago.yaml
@ -7,40 +7,50 @@ package:
|
|||||||
- console
|
- console
|
||||||
- control
|
- control
|
||||||
- datetime
|
- datetime
|
||||||
- dotenv
|
|
||||||
- effect
|
- effect
|
||||||
- either
|
- either
|
||||||
- enums
|
- enums
|
||||||
- exceptions
|
- exceptions
|
||||||
- filterable
|
|
||||||
- foldable-traversable
|
- foldable-traversable
|
||||||
- foreign
|
- foreign
|
||||||
- identity
|
- foreign-object
|
||||||
- integers
|
- integers
|
||||||
|
- js-date
|
||||||
- maybe
|
- maybe
|
||||||
- newtype
|
- newtype
|
||||||
- node-buffer
|
- node-buffer
|
||||||
|
- node-event-emitter
|
||||||
- node-path
|
- node-path
|
||||||
- node-process
|
|
||||||
- node-streams
|
|
||||||
- node-url
|
|
||||||
- nullable
|
- nullable
|
||||||
- ordered-collections
|
- ordered-collections
|
||||||
- parallel
|
- parallel
|
||||||
- prelude
|
- prelude
|
||||||
- record-extra
|
- record
|
||||||
- simple-json
|
- simple-json
|
||||||
- spec
|
|
||||||
- st
|
|
||||||
- strings
|
- strings
|
||||||
- tailrec
|
- stringutils
|
||||||
- transformers
|
- transformers
|
||||||
- tuples
|
- tuples
|
||||||
|
- typelevel-prelude
|
||||||
- unsafe-coerce
|
- unsafe-coerce
|
||||||
|
- variant
|
||||||
- web-cssom
|
- web-cssom
|
||||||
- web-dom
|
- web-dom
|
||||||
- web-html
|
- web-html
|
||||||
name: puppeteer
|
name: puppeteer
|
||||||
|
test:
|
||||||
|
dependencies:
|
||||||
|
- dotenv
|
||||||
|
- filterable
|
||||||
|
- identity
|
||||||
|
- node-event-emitter
|
||||||
|
- node-process
|
||||||
|
- node-streams
|
||||||
|
- node-url
|
||||||
|
- spec
|
||||||
|
- st
|
||||||
|
- tailrec
|
||||||
|
main: Test.Main
|
||||||
workspace:
|
workspace:
|
||||||
extra_packages: {}
|
extra_packages: {}
|
||||||
package_set:
|
package_set:
|
||||||
|
@ -2,22 +2,27 @@ module Puppeteer.FFI (mapToRecord, maybeToUndefined, mergeRecords, unsafeMaybeTo
|
|||||||
|
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
import Control.Monad.Error.Class (catchError, throwError)
|
||||||
import Control.Monad.Except (runExcept)
|
import Control.Monad.Except (runExcept)
|
||||||
import Control.Promise (Promise)
|
import Control.Promise (Promise)
|
||||||
import Control.Promise as Promise
|
import Control.Promise as Promise
|
||||||
import Data.Array as Array
|
import Data.Array as Array
|
||||||
import Data.Either (either)
|
import Data.Either (either)
|
||||||
|
import Data.Foldable (any)
|
||||||
import Data.FoldableWithIndex (foldlWithIndex)
|
import Data.FoldableWithIndex (foldlWithIndex)
|
||||||
import Data.Map (Map)
|
import Data.Map (Map)
|
||||||
import Data.Map as Map
|
import Data.Map as Map
|
||||||
import Data.Maybe (Maybe)
|
import Data.Maybe (Maybe)
|
||||||
import Data.Nullable (Nullable)
|
import Data.Nullable (Nullable)
|
||||||
import Data.Nullable as Nullable
|
import Data.Nullable as Nullable
|
||||||
|
import Data.String as String
|
||||||
|
import Data.String.Utils (includes) as String
|
||||||
import Data.Tuple (Tuple(..))
|
import Data.Tuple (Tuple(..))
|
||||||
import Effect (Effect)
|
import Effect (Effect)
|
||||||
import Effect.Aff (Aff)
|
import Effect.Aff (Aff)
|
||||||
import Effect.Class (liftEffect)
|
import Effect.Class (liftEffect)
|
||||||
import Effect.Exception (error)
|
import Effect.Exception (error)
|
||||||
|
import Effect.Exception as Error
|
||||||
import Foreign (Foreign, unsafeReadTagged)
|
import Foreign (Foreign, unsafeReadTagged)
|
||||||
import Simple.JSON (class WriteForeign)
|
import Simple.JSON (class WriteForeign)
|
||||||
|
|
||||||
@ -39,10 +44,30 @@ unsafeMaybeToUndefined :: forall a. Maybe a -> Foreign
|
|||||||
unsafeMaybeToUndefined = _maybeToUndefined Nullable.toNullable
|
unsafeMaybeToUndefined = _maybeToUndefined Nullable.toNullable
|
||||||
|
|
||||||
promiseToAff :: forall a. Effect (Promise a) -> Aff a
|
promiseToAff :: forall a. Effect (Promise a) -> Aff a
|
||||||
promiseToAff =
|
promiseToAff work =
|
||||||
let
|
let
|
||||||
err e = either (const $ error $ anyToString e) identity
|
err e = either (const $ error $ anyToString e) identity
|
||||||
$ runExcept
|
$ runExcept
|
||||||
$ unsafeReadTagged "Error" e
|
$ unsafeReadTagged "Error" e
|
||||||
|
|
||||||
|
retryErrorsMatching =
|
||||||
|
[ "execution context destroyed"
|
||||||
|
]
|
||||||
|
|
||||||
|
shouldRetry e =
|
||||||
|
any
|
||||||
|
(\retryErr -> String.includes retryErr $ String.trim (Error.message e))
|
||||||
|
retryErrorsMatching
|
||||||
|
|
||||||
|
attempt = do
|
||||||
|
promise <- liftEffect work
|
||||||
|
Promise.toAff' err promise
|
||||||
|
|
||||||
|
retry e =
|
||||||
|
if shouldRetry e then do
|
||||||
|
promise <- liftEffect work
|
||||||
|
Promise.toAff' err promise
|
||||||
|
else
|
||||||
|
throwError e
|
||||||
in
|
in
|
||||||
flip bind (Promise.toAff' err) <<< liftEffect
|
catchError attempt retry
|
||||||
|
Loading…
Reference in New Issue
Block a user