well-typed / grapesy

Native Haskell gRPC client and server based on `http2`
Other
31 stars 4 forks source link

Catch pure exceptions when calling `buildMetadata` #126

Closed edsko closed 2 months ago

edsko commented 2 months ago

This can be helpful when there are bugs constructing the metadata, for example constructing an ASCII header with a non-ASCII value. Prior to this commit this would result in the server disconnecting without any kind of helpful error message, because the exception was actually triggered deep in the bowels of http2. We now trigger it earlier, so that we throw the appropriate exception. For example:

CustomMetadata "x-wrong-header" "\x00"

will result in

Invalid: CustomMetadata "x-wrong-header" "\NUL" at <callstack>

on the server, which will then propagate to the client as

GrpcException {
    grpcError = GrpcUnknown
  , grpcErrorMessage = Just "Invalid: CustomMetadata \"x-wrong-header\" \"\\NUL\" at <callstack>"
  , grpcErrorMetadata = []
}