Skip to content

Commit

Permalink
fix: review -> fine grain tryAndCache errors
Browse files Browse the repository at this point in the history
  • Loading branch information
srghma committed Nov 19, 2020
1 parent 89c37e4 commit e7428d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Lunapark.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Lunapark


import Lunapark.API (Interpreter(..), runInterpreter, LunaparkBaseEffects, HandleLunaparkInput, handleLunapark, init, interpret, interpretW3CActions, jsonWireActions, runLunapark, runLunaparkActions, w3cActions)
import Lunapark.Error (Error(..), printError)
import Lunapark.Error (Error(..), CachingError(..), printError)
import Lunapark.ActionF (ActionF(..), LUNAPARK_ACTIONS, TouchF(..), LunaparkActionsEffect, _lunaparkActions, buttonDown, buttonUp, click, doubleClick, doubleTap, flick, liftAction, longTap, moveTo, pause, scroll, sendKeys, tap, touchDown, touchUp)
import Lunapark.LunaparkF (ElementF(..), LUNAPARK, LunaparkF(..), LunaparkEffect, _lunapark, acceptAlert, addCookie, back, childElement, childElements, clearElement, clickElement, closeWindow, deleteAllCookies, deleteCookie, dismissAlert, elementScreenshot, executeScript, executeScriptAsync, findElement, findElements, forward, fullscreenWindow, getAlertText, getAllCookies, getAttribute, getCookie, getCss, getProperty, getRectangle, getTagName, getText, getTimeouts, getTitle, getUrl, getWindowHandle, getWindowHandles, getWindowRectangle, go, isDisplayed, isEnabled, isSelected, liftLunapark, maximizeWindow, minimizeWindow, performActions, quit, refresh, releaseActions, screenshot, sendAlertText, sendKeysElement, setTimeouts, setWindowRectangle, status, submitElement, switchToFrame, switchToParentFrame, switchToWindow)
import Lunapark.WebdriverError (WebdriverError, WebdriverErrorType(..), fromJson, fromStringCode, toStringCode)
7 changes: 2 additions & 5 deletions src/Lunapark/API.purs
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,11 @@ handleLunapark inp = case _ of

tryAndCache a. String Array (Run (LunaparkBaseEffects r) a) Run (LunaparkBaseEffects r) a
tryAndCache key actions = do
let emptyCases = RE.throw $ LE.UserError $ "No valid cases for " <> key <> " caching"
let incorrectCache = RE.throw $ LE.UserError $ "Fallback for " <> key <> " error"

mp ← R.liftEffect $ Ref.read inp.requestMapRef
case Map.lookup key mp of
Just ix → case A.index actions ix of
Just action → action
NothingincorrectCache
NothingRE.throw $ LE.CachingError $ LE.IncorrectCache key
Nothing
let
go ix acc act =
Expand All @@ -557,7 +554,7 @@ handleLunapark inp = case _ of
pure a
in catch try' \_ → acc
in
FI.foldlWithIndex go emptyCases actions
FI.foldlWithIndex go (RE.throw $ LE.CachingError $ LE.EmptyCases key) actions

inSession LP.EndpointPart
inSession = LP.InSession inp.session
11 changes: 9 additions & 2 deletions src/Lunapark/Error.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import Affjax as N
import Lunapark.WebdriverError as LWE
import Data.Argonaut.Decode (JsonDecodeError, printJsonDecodeError) as J

data CachingError
= EmptyCases String
| IncorrectCache String

data Error
= JsonDecodeError J.JsonDecodeError
| WebdriverError LWE.WebdriverError
| AffjaxError N.Error
| UserError String
| CachingError CachingError

printError :: Error -> String
printError =
Expand All @@ -21,4 +25,7 @@ printError =
<> " message: " <> webdriverError.message <> "\n"
<> " stacktrace: " <> webdriverError.stacktrace
AffjaxError affjaxError -> N.printError affjaxError
UserError s -> s
CachingError cachingError -> "Error during caching:\n" <>
case cachingError of
EmptyCases key -> "No valid cases for " <> key <> " caching"
IncorrectCache key -> "Fallback for " <> key <> " error"

0 comments on commit e7428d9

Please sign in to comment.