Help with Env/HasScope stuff
Closed this issue · 1 comments
runeksvendsen commented
So I'm trying to run all the MonadGoogle
functions I've created, but I get the following error when I try to run everything using runResourceT . runGoogle (storeEnv :: Env '[AuthDatastore])
/Users/rune/IdeaProjects/paychan-datastore/src/Test.hs:40:62: error:
• Couldn't match type ‘Network.Google.Auth.Scope.HasScope'
'[AuthDatastore] (Scopes BeginTransactionResponse)’
with ‘'True’
arising from a use of ‘testDB’
• In the second argument of ‘($)’, namely ‘testDB pid tstData’
In a stmt of a 'do' block:
runResourceT . runGoogle (env :: Env '[AuthDatastore])
$ testDB pid tstData
In the expression:
do { putStrLn $ "Using project: " ++ cs pid;
env <- defaultAppDatastoreEnv;
tstData <- genTestData numPayments;
runResourceT . runGoogle (env :: Env '[AuthDatastore])
$ testDB pid tstData }
Relevant snippet (error appears at testDB pid tstData
in runPaymentTest
- line 40 in this file):
type AuthDatastore = "https://www.googleapis.com/auth/datastore"
runPaymentTest :: ProjectId -> Word -> IO Int
runPaymentTest pid numPayments = do
putStrLn $ "Using project: " ++ cs pid
storeEnv <- defaultAppDatastoreEnv
tstData <- genTestData numPayments
-- Run
runResourceT . runGoogle (storeEnv :: Env '[AuthDatastore]) $
-- ERROR: "Couldn't match type
-- HasScope' '[AuthDatastore] (Scopes BeginTransactionResponse)’ with ‘'True’"
testDB pid tstData
testDB :: ( MonadCatch m
, MonadGoogle '[AuthDatastore] m
, HasScope '[AuthDatastore] BeginTransactionResponse
, HasScope '[AuthDatastore] LookupResponse
, HasScope '[AuthDatastore] RollbackResponse
, HasScope '[AuthDatastore] CommitResponse )
=> ProjectId -> Pay.ChannelPairResult -> m Int
testDB pid Pay.ChannelPairResult{..} = do
let sampleRecvChan = Pay.recvChan resInitPair
sampleKey = Pay.getSenderPubKey sampleRecvChan
paymentList = reverse $ init resPayList
DB.insertChan pid sampleRecvChan
-- Safe lookup + update/rollback
res <- M.forM paymentList (doPayment pid sampleKey)
return $ length res
defaultAppDatastoreEnv :: IO (Env '[AuthDatastore])
defaultAppDatastoreEnv = do
manager <- HTTP.newManager HTTP.tlsManagerSettings
logger <- Google.newLogger Google.Error stderr
Google.newEnv <&>
(envLogger .~ logger) .
(envScopes .~ datastoreScope) .
(envManager .~ manager)
Relevant snippet from gogol-datastore
:
runeksvendsen commented
Alright, I figured it out. I should be referencing the Project types (eg. ProjectsBeginTransaction), rather than the response types (BeginTransaction).
It finally compiles. Hooray!