Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code generation with generateLambdaDispatcher leads to warnings (Update: Addressed by upcoming 4.0.0) #82

Open
andys8 opened this issue Jul 16, 2020 · 7 comments

Comments

@andys8
Copy link
Contributor

andys8 commented Jul 16, 2020

With

generateLambdaDispatcher UseWithAPIGateway defaultDispatcherOptions

I'm currently seeing these warnings:

/app/Main.hs:58:1: warning: [-Wunused-matches]
    Defined but not used: ‘executionUuid’
   |
58 | generateLambdaDispatcher UseWithAPIGateway defaultDispatcherOptions
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/app/Main.hs:58:1: warning: [-Wunused-matches]
    Defined but not used: ‘eventObject’
   |
58 | generateLambdaDispatcher UseWithAPIGateway defaultDispatcherOptions
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/app/Main.hs:58:1: warning: [-Wunused-matches]
    Defined but not used: ‘contextObject’
   |
58 | generateLambdaDispatcher UseWithAPIGateway defaultDispatcherOptions
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/app/Main.hs:58:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature:
      run :: Applicative f =>
             LambdaOptions context
             -> f (Either
                     aws-lambda-haskell-runtime-3.0.1:Aws.Lambda.Runtime.Common.LambdaError
                     b)
   |
58 | generateLambdaDispatcher UseWithAPIGateway defaultDispatcherOptions
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/app/Main.hs:58:1: warning: [-Wmissing-signatures]
    Top-level binding with no type signature: main :: IO ()
   |
58 | generateLambdaDispatcher UseWithAPIGateway defaultDispatcherOptions
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Is it possible to get rid of them?

Version 3.0.1

@andys8
Copy link
Contributor Author

andys8 commented Jul 17, 2020

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

@andys8
Copy link
Contributor Author

andys8 commented Jul 17, 2020

I tried to inline the generated code, but it looks like that's not possible because ApiGatewayLambdaError is not exposed.

ApiGatewayLambdaError (ApiGatewayResponse ApiGatewayResponseBody)

@andys8
Copy link
Contributor Author

andys8 commented Jul 17, 2020

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"))) }

@andys8
Copy link
Contributor Author

andys8 commented Jul 17, 2020

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!

& filter (Text.isPrefixOf "handler :: " . Text.pack)

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"

@andys8
Copy link
Contributor Author

andys8 commented Jul 17, 2020

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 :)

@NickSeagull
Copy link
Member

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 :)

@andys8
Copy link
Contributor Author

andys8 commented Jul 17, 2020

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.

@andys8 andys8 changed the title Code generation with generateLambdaDispatcher leads to warnings Code generation with generateLambdaDispatcher leads to warnings (Update: Addressed by upcoming 4.0.0) Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants