Open andys8 opened 4 years ago
Okay, I think the actual issue, is that the handler
function is not picked up and the generated code looks like tihs:
app/Main.hs:62:1-67: Splicing declarations
generateLambdaDispatcher UseWithAPIGateway defaultDispatcherOptions
======>
main = (runLambda initializeContext) run
run
LambdaOptions {functionHandler = functionHandler,
contextObject = contextObject, eventObject = eventObject,
executionUuid = executionUuid}
= case functionHandler of {
_ -> ((pure
. (Left
. (aws-lambda-haskell-runtime-3.0.1:Aws.Lambda.Runtime.Common.ApiGatewayLambdaError
. (mkApiGatewayResponse 500 . toApiGatewayResponseBody))))
$ ("Handler "
<> (functionHandler <> " does not exist on project"))) }
Will look into it
I tried to inline the generated code, but it looks like that's not possible because ApiGatewayLambdaError
is not exposed.
This (minimal) apigateway example:
initializeContext :: IO ()
initializeContext = return ()
handler
:: ApiGatewayRequest Text
-> Context ()
-> IO (Either (ApiGatewayResponse Text) (ApiGatewayResponse Text))
handler request context = return $ Right $ mkApiGatewayResponse 200 "OK"
generateLambdaDispatcher UseWithAPIGateway defaultDispatcherOptions
results in:
main = (runLambda initializeContext) run
run
LambdaOptions {functionHandler = functionHandler,
contextObject = contextObject, eventObject = eventObject,
executionUuid = executionUuid}
= case functionHandler of {
_ -> ((pure
. (Left
. (aws-lambda-haskell-runtime-3.0.1:Aws.Lambda.Runtime.Common.ApiGatewayLambdaError
. (mkApiGatewayResponse 500 . toApiGatewayResponseBody))))
$ ("Handler "
<> (functionHandler <> " does not exist on project"))) }
Okay, I think the issue might actually be, that the formatting of the type signature is in multiple lines. The project is formatted with brittany
and ::
is not in the same line as handler
. Because of this, it won't be picked up!
Formatting it like this, is working.
type Req = ApiGatewayRequest Text
type Res = ApiGatewayResponse Text
handler :: Req -> Context () -> IO (Either Res Res)
handler request context = return $ Right $ mkApiGatewayResponse 200 "OK"
With the handler being recognized there are less warnings:
/app/app/Main.hs:68:1: error: [-Wunused-matches, -Werror=unused-matches]
Defined but not used: ‘executionUuid’
|
68 | generateLambdaDispatcher UseWithAPIGateway defaultDispatcherOptions
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/app/app/Main.hs:68:1: error: [-Wmissing-signatures, -Werror=missing-signatures]
Top-level binding with no type signature:
run :: LambdaOptions Token.Handle
-> IO
(Either
aws-lambda-haskell-runtime-3.0.1:Aws.Lambda.Runtime.Common.LambdaError
LambdaResult)
|
68 | generateLambdaDispatcher UseWithAPIGateway defaultDispatcherOptions
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/app/app/Main.hs:68:1: error: [-Wmissing-signatures, -Werror=missing-signatures]
Top-level binding with no type signature: main :: IO ()
|
68 | generateLambdaDispatcher UseWithAPIGateway defaultDispatcherOptions
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sorry for spamming comments :)
Hey! Thanks so much for writing such a detailed issue!
I'm currently working on #81 so all Template Haskell code will go away, and with it, all the warnings :)
Nice. I had a look at the changes, and it looks like the search for "handler ::"
will also be removed, and therefore a fix is probably not necessary.
I'd leave this issue open for documentation and close it with the rel are of 4.0.0
. Looking forward to it.
With
I'm currently seeing these warnings:
Is it possible to get rid of them?
Version 3.0.1