Comments (3)
Hello, I was trying to use mu-haskell for grpc calls and get some errors out of it. But on any grpc errors, I just get "not enough bytes". My guess is that it is coming from here, but I am not sure:
http2-grpc-haskell/http2-client-grpc/src/Network/GRPC/Client.hs
Lines 140 to 145 in fcc9e6f
Here is some code which reproduces the error:
cabal.project:
source-repository-package
type: git
location: https://github.com/higherkindness/mu-haskell
tag: 4cd6560d16bddee9ef79cbfce4a28b3b8922d29f
subdir: core/schema
source-repository-package
type: git
location: https://github.com/higherkindness/mu-haskell
tag: 4cd6560d16bddee9ef79cbfce4a28b3b8922d29f
subdir: adapter/protobuf
source-repository-package
type: git
location: https://github.com/haskell-grpc-native/http2-grpc-haskell.git
tag: fcc9e6f76df0ee37313b10697a3868552555cedd
subdir: http2-client-grpc
source-repository-package
type: git
location: https://github.com/akshaymankar/tracing.git
tag: ef4d6337540603482afa89aa4f067574e089bf46
packages: ./
Main.hs:
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-partial-type-signatures #-}
module Main where
import Control.Concurrent
import Control.Concurrent.Async
import Control.Monad (forever)
import Control.Monad.Except
import Data.Text (Text)
import GHC.TypeLits
import Mu.Adapter.ProtoBuf
import Mu.GRpc.Client.Optics
import Mu.GRpc.Client.TyApps
import Mu.GRpc.Server
import Mu.Rpc
import Mu.Schema
import Mu.Server
main :: IO ()
main =
concurrently_ serve (forever $ query >> threadDelay 1000000)
type MySchema = '[ 'DRecord "Foo" '[ 'FieldDef "foo" ('TPrimitive Text)]]
type MyService =
'Package
('Just "pkg")
'[ 'Service
"MyService"
'[ 'Method
"identityFoo"
'[ 'ArgSingle ('Nothing :: Maybe Symbol) ('SchemaRef MySchema "Foo")]
('RetSingle ('SchemaRef MySchema "Foo"))
]
]
type instance
AnnotatedSchema ProtoBufAnnotation MySchema =
'[ 'AnnField "Foo" "foo" ('ProtoBufId 1 '[])]
type Foo = Term MySchema (MySchema :/: "Foo")
identityFoo :: MonadServer m => Foo -> m Foo
identityFoo _ = throwError $ ServerError NotFound "nothing to see here"
-- identityFoo = pure
service :: MonadServer m => SingleServerT i MyService m _
service = singleService (method @"identityFoo" identityFoo)
serve :: IO ()
serve = runGRpcApp msgProtoBuf 8080 service
mkClient :: IO GrpcClient
mkClient = assertRight =<< setupGrpcClient' (grpcClientConfigSimple "127.0.0.1" 8080 False)
assertRight :: Show a => Either a b -> IO b
assertRight = either (error . show) pure
query :: IO ()
query = do
c <- mkClient
r :: GRpcReply Foo <- gRpcCall @'MsgProtoBuf @MyService @"MyService" @"identityFoo" c bar
case r of
GRpcErrorString str -> putStrLn $ "GRpcError: " <> str
GRpcOk x -> putStrLn $ "Ok: " <> show x
_ -> putStrLn "Unexpected!"
bar :: Foo
bar = record1 "bar"
from http2-grpc-haskell.
I looked more deeply into this and found that this happens because this part of code doesn't look at :status
or grpc-status
in the headers before trying to decode the body. In my case the server responds with a 404, this could also be one of 5xx responses.
This raises a design of question about the RawReply
type. As of now it is defined as:
http2-grpc-haskell/http2-client-grpc/src/Network/GRPC/Client.hs
Lines 104 to 114 in fcc9e6f
The ErrorCode
is the HTTP2 error code which doesn't seem enough to express gRPC specific of errors. Would you be open to introducing another type for gRPC Errors and replace this ErrorCode
with this new type?
from http2-grpc-haskell.
Actually changing ErrorCode
is not necessary, changing the third item in the tuple from Either String a
to something like Either GRPCError a
would also solve the problem.
from http2-grpc-haskell.
Related Issues (20)
- Invalid HTTP header field HOT 2
- Implement Server Reflection
- Have some logo HOT 1
- Add a set of examples HOT 6
- Add a benchmark tool HOT 1
- Add performance counter hooks
- Add some form of connection manager for the client HOT 1
- Document usage with pretty pictures HOT 1
- Remove the "forked from lucasdicioccio/http2-grpc-haskell" thing from GitHub HOT 2
- Import work around Bazel HOT 1
- InvalidState: "stream error" HOT 1
- Upper bound on proto3-wire dependency breaks current builds on Nix (Stack + Nix integration)
- include .cabal file in http2-grpc-types package HOT 7
- Support unix sockets in http2-client-grpc HOT 2
- Clarify the goals of the project
- grpc client is insecure by default but doesn't advertise it in any way. HOT 5
- Resource Safe Stream Cancellation
- http2-grpc-proto-lens on Hackage is outdated HOT 2
- Examples of using these packages
- Cannot build on GHC 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from http2-grpc-haskell.