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

Error in generated Haskell file from latest compile-proto-file binary #119

Open
nwaywood opened this issue Feb 3, 2020 · 15 comments · Fixed by #140
Open

Error in generated Haskell file from latest compile-proto-file binary #119

nwaywood opened this issue Feb 3, 2020 · 15 comments · Fixed by #140
Assignees

Comments

@nwaywood
Copy link

nwaywood commented Feb 3, 2020

I just finished doing the Arithmetic tutorial here https:/awakesecurity/gRPC-haskell/blob/master/examples/tutorial/TUTORIAL.md

When I run it using the Arithmetic.hs file that was provided in the repo everything works perfectly.

However when I try and run it using a freshly generated Arithmetic.hs file from compile-proto-file, it fails to compile with the following error:

grpc-haskell> [1 of 2] Compiling Arithmetic
grpc-haskell>
grpc-haskell> /Users/nick/code/src/github.com/awakesecurity/gRPC-haskell/examples/tutorial/Arithmetic.hs:161:66: error:
grpc-haskell>     • Couldn't match expected type ‘Hs.Maybe
grpc-haskell>                                       (HsJSONPB.SwaggerType
grpc-haskell>                                          'swagger2-2.4:Data.Swagger.Internal.SwaggerKindSchema)’
grpc-haskell>                   with actual type ‘HsJSONPB.SwaggerType
grpc-haskell>                                       'swagger2-2.4:Data.Swagger.Internal.SwaggerKindSchema’
grpc-haskell>     • In the ‘_paramSchemaType’ field of a record
grpc-haskell>       In the ‘_schemaParamSchema’ field of a record
grpc-haskell>       In the ‘_namedSchemaSchema’ field of a record
grpc-haskell>     |
grpc-haskell> 161 |                                                                  HsJSONPB.SwaggerObject},
grpc-haskell>     |                                                                  ^^^^^^^^^^^^^^^^^^^^^^
grpc-haskell>
grpc-haskell> /Users/nick/code/src/github.com/awakesecurity/gRPC-haskell/examples/tutorial/Arithmetic.hs:216:66: error:
grpc-haskell>     • Couldn't match expected type ‘Hs.Maybe
grpc-haskell>                                       (HsJSONPB.SwaggerType
grpc-haskell>                                          'swagger2-2.4:Data.Swagger.Internal.SwaggerKindSchema)’
grpc-haskell>                   with actual type ‘HsJSONPB.SwaggerType
grpc-haskell>                                       'swagger2-2.4:Data.Swagger.Internal.SwaggerKindSchema’
grpc-haskell>     • In the ‘_paramSchemaType’ field of a record
grpc-haskell>       In the ‘_schemaParamSchema’ field of a record
grpc-haskell>       In the ‘_namedSchemaSchema’ field of a record
grpc-haskell>     |
grpc-haskell> 216 |                                                                  HsJSONPB.SwaggerObject},
grpc-haskell>     |                                                                  ^^^^^^^^^^^^^^^^^^^^^^
grpc-haskell>

If I manually edit the generated Arithmetic.hs file and change lines 161 and 216 from

HsJSONPB.SwaggerObject},

to

Hs.Just HsJSONPB.SwaggerObject},

It works again.

@nwaywood nwaywood changed the title Error in generated Haskell file from latest compile-proto-file Error in generated Haskell file from latest compile-proto-file binary Feb 3, 2020
Gabriella439 added a commit to awakesecurity/gRPC-haskell that referenced this issue Feb 10, 2020
@Gabriella439
Copy link
Contributor

@nwaywood: What version of proto3-suite are you using to obtain the compile-proto-file executable? The reason I ask is that I just attempted to update the Arithmetic.hs example from a recent proto3-suite revision and did not run into the problem that you described.

The only issue I found was a missing deepseq dependency which I have a pull request up to fix:

awakesecurity/gRPC-haskell#102

Gabriella439 added a commit to awakesecurity/gRPC-haskell that referenced this issue Feb 10, 2020
@nwaywood
Copy link
Author

I am on this commit 3f6dd6f

@Gabriella439
Copy link
Contributor

@nwaywood: Hmmm, that's weird because I believe that I'm using that same revision, too. Could you attach the generated Arithmetic.hs that you got? I'll also double-check the version of compile-proto-file that I'm using

@nwaywood
Copy link
Author

Arithmetic.txt

Here is the Arithmetic file that is generated by running the command

compile-proto-file --proto arithmetic.proto --out .

from the tutorial directory (apologies for the file extension being .txt, I had to rename it from .hs to .txt for github to let me upload it).

@DeepakKapiswe
Copy link
Contributor

DeepakKapiswe commented Apr 1, 2020

@Gabriel439 I'm also getting a very similar error, I'm currently using the latest patch on master

proxyServer>     • Couldn't match expected type ‘Hs.Maybe
proxyServer>                                       (HsJSONPB.SwaggerType
proxyServer>                                          'swagger2-2.5:Data.Swagger.Internal.SwaggerKindSchema)’
proxyServer>                   with actual type ‘HsJSONPB.SwaggerType
proxyServer>                                       'swagger2-2.5:Data.Swagger.Internal.SwaggerKindSchema’
proxyServer>     • In the ‘_paramSchemaType’ field of a record
proxyServer>       In the ‘_schemaParamSchema’ field of a record
proxyServer>       In the ‘_namedSchemaSchema’ field of a record
proxyServer>       |
proxyServer> 17792 |                                                                  HsJSONPB.SwaggerObject},``` 

@tim2CF
Copy link
Collaborator

tim2CF commented May 13, 2020

I got the same error, tried to downgrade swagger to 2.3.1.1 and got different error

    * Impossible to have an instance HsJSONPB.ToSchema Hs.ByteString.
      Please, use a newtype wrapper around Hs.ByteString instead.
      Consider using byteSchema or binarySchema templates.
    * In the expression: HsJSONPB.declareSchemaRef
      In an equation for `declare_dest_custom_records':
          declare_dest_custom_records = HsJSONPB.declareSchemaRef
      In the expression:
        do let declare_dest = HsJSONPB.declareSchemaRef
           sendRequestDest <- declare_dest Proxy.Proxy
           let declare_dest_string = HsJSONPB.declareSchemaRef
           sendRequestDestString <- declare_dest_string Proxy.Proxy
           ....
     |
2417 |       let declare_dest_custom_records = HsJSONPB.declareSchemaRef
     |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^

@tim2CF
Copy link
Collaborator

tim2CF commented May 13, 2020

@Gabriel439 I see some code in proto3-suite related to this bug (ToSchema instance of ByteString), but seems it's not working in my case. What do you think, how I can workaround it?

@tim2CF
Copy link
Collaborator

tim2CF commented May 13, 2020

I actually know which types are causing these errors, here is example
https:/lightningnetwork/lnd/blob/1bd211a7228d2f13ecaf514f611738837c057d94/lnrpc/rpc.proto#L840

@tim2CF
Copy link
Collaborator

tim2CF commented May 15, 2020

Not sure it is right solution or not, but I worked it around with this orphan instance
https:/coingaming/lnd-client/blob/d6971ae41da8c8112a65b805ba49106bcad3edf6/src/LndGrpc/Orphans.hs#L11-L12

@nwaywood
Copy link
Author

nwaywood commented Sep 1, 2020

I just updated to the latest version of the compile-proto-file binary and can confirm that I now have the same issue as @tim2CF, his solution here solves it for me as well.

This is the only issue I am now having with the latest binary, the original issue is no longer happening :)

@Gabriella439
Copy link
Contributor

Fix is up here: #140

@nwaywood
Copy link
Author

nwaywood commented Sep 3, 2020

@Gabriel439 I just tried #140 and I am still getting the error described here

@Gabriella439 Gabriella439 reopened this Sep 3, 2020
@nwaywood
Copy link
Author

nwaywood commented Sep 3, 2020

In case some more detail may be useful for you...

This is the snippet of code that I need to add to one of the generated hs files in my project to make it work.

And as @tim2CF mentioned, I am assuming that the reason why I'm only having issues with that generated file and none of my other ones is because that source proto file contains a map type

@Gabriella439
Copy link
Contributor

@nwaywood: I think I will need more detailed reproduction instructions, because I'm no longer able to reproduce the problem for the Arithmetic.hs file on master

@nwaywood
Copy link
Author

nwaywood commented Sep 7, 2020

@Gabriel439 yes I don't think the issue will happen with the Arithmetic.hs file anymore since the issue seems to be with the map type (map documentation) and Arithmetic.proto contains no map types.

If you don't mind using my project, https:/hyperledger-labs/fabric-chaincode-haskell, then reproduction is very easy.

git clone [email protected]:hyperledger-labs/fabric-chaincode-haskell.git
cd fabric-chaincode-haskell/protos
./generate.sh
cd ..
stack build

The stack build will fail on an error similar to the one @tim2CF described here. In the case of my project, it is failing due to this map type and I currently fix it manually by adding the code as described in my readme

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

Successfully merging a pull request may close this issue.

5 participants