awakesecurity / proto3-suite

Haskell Protobuf Implementation
https://hackage.haskell.org/package/proto3-suite
Other
81 stars 56 forks source link

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

Open nwaywood opened 4 years ago

nwaywood commented 4 years ago

I just finished doing the Arithmetic tutorial here https://github.com/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.

Gabriella439 commented 4 years ago

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

https://github.com/awakesecurity/gRPC-haskell/pull/102

nwaywood commented 4 years ago

I am on this commit https://github.com/awakesecurity/proto3-suite/commit/3f6dd6f612cf2eba3c05798926ff924b0d5ab4fa

Gabriella439 commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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

tim2CF commented 4 years ago

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

nwaywood commented 4 years ago

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 commented 4 years ago

Fix is up here: https://github.com/awakesecurity/proto3-suite/pull/140

nwaywood commented 4 years ago

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

nwaywood commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

@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://github.com/hyperledger-labs/fabric-chaincode-haskell, then reproduction is very easy.

git clone git@github.com: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