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
|
||||
- control
|
||||
- datetime
|
||||
- dotenv
|
||||
- effect
|
||||
- either
|
||||
- enums
|
||||
- exceptions
|
||||
- filterable
|
||||
- foldable-traversable
|
||||
- foreign
|
||||
- identity
|
||||
- foreign-object
|
||||
- integers
|
||||
- js-date
|
||||
- maybe
|
||||
- newtype
|
||||
- node-buffer
|
||||
- node-event-emitter
|
||||
- node-path
|
||||
- node-process
|
||||
- node-streams
|
||||
- node-url
|
||||
- nullable
|
||||
- ordered-collections
|
||||
- parallel
|
||||
- prelude
|
||||
- record-extra
|
||||
- record
|
||||
- simple-json
|
||||
- spec
|
||||
- st
|
||||
- strings
|
||||
- tailrec
|
||||
- stringutils
|
||||
- transformers
|
||||
- tuples
|
||||
- typelevel-prelude
|
||||
- unsafe-coerce
|
||||
- variant
|
||||
- web-cssom
|
||||
- web-dom
|
||||
- web-html
|
||||
name: puppeteer
|
||||
test:
|
||||
dependencies:
|
||||
- dotenv
|
||||
- filterable
|
||||
- identity
|
||||
- node-event-emitter
|
||||
- node-process
|
||||
- node-streams
|
||||
- node-url
|
||||
- spec
|
||||
- st
|
||||
- tailrec
|
||||
main: Test.Main
|
||||
workspace:
|
||||
extra_packages: {}
|
||||
package_set:
|
||||
|
@ -2,22 +2,27 @@ module Puppeteer.FFI (mapToRecord, maybeToUndefined, mergeRecords, unsafeMaybeTo
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Monad.Error.Class (catchError, throwError)
|
||||
import Control.Monad.Except (runExcept)
|
||||
import Control.Promise (Promise)
|
||||
import Control.Promise as Promise
|
||||
import Data.Array as Array
|
||||
import Data.Either (either)
|
||||
import Data.Foldable (any)
|
||||
import Data.FoldableWithIndex (foldlWithIndex)
|
||||
import Data.Map (Map)
|
||||
import Data.Map as Map
|
||||
import Data.Maybe (Maybe)
|
||||
import Data.Nullable (Nullable)
|
||||
import Data.Nullable as Nullable
|
||||
import Data.String as String
|
||||
import Data.String.Utils (includes) as String
|
||||
import Data.Tuple (Tuple(..))
|
||||
import Effect (Effect)
|
||||
import Effect.Aff (Aff)
|
||||
import Effect.Class (liftEffect)
|
||||
import Effect.Exception (error)
|
||||
import Effect.Exception as Error
|
||||
import Foreign (Foreign, unsafeReadTagged)
|
||||
import Simple.JSON (class WriteForeign)
|
||||
|
||||
@ -39,10 +44,30 @@ unsafeMaybeToUndefined :: forall a. Maybe a -> Foreign
|
||||
unsafeMaybeToUndefined = _maybeToUndefined Nullable.toNullable
|
||||
|
||||
promiseToAff :: forall a. Effect (Promise a) -> Aff a
|
||||
promiseToAff =
|
||||
promiseToAff work =
|
||||
let
|
||||
err e = either (const $ error $ anyToString e) identity
|
||||
$ runExcept
|
||||
$ 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
|
||||
flip bind (Promise.toAff' err) <<< liftEffect
|
||||
catchError attempt retry
|
||||
|
Loading…
Reference in New Issue
Block a user