Skip to content

Need to be able to handle low-level marshalling errors #828

@torkelrogstad

Description

@torkelrogstad

Is your feature request related to a problem? Please describe.
My code is somehow constructing Protobuf messages that fail to encode: timestamppb.Timestamp values with second values larger than maxSecondsInDuration. That's on me - but the current tools for picking up the error is insufficient.

Reproduce:

  1. Create a timestamppb.Timestamp message with Seconds set to 315576000001.
  2. Return this message as part of a response.
  3. Call the endpoint in such a way that protojson encoding is used: curl -H "content-type: application/json" -X POST --fail-with-body http://server/service/Endpoint
  4. curl fails: curl: (22) The requested URL returned error: 500 {"code":"internal","message":"marshal message: proto: google.protobuf.Timestamp: seconds out of range 315576000000"}
  5. Observe that there's no way within interceptors or other user-available mechanisms to handle this error.

Describe the solution you'd like
From what I can observe the error is returned from h.implementation(ctx, connCloser) here:

_ = connCloser.Close(h.implementation(ctx, connCloser))

It would be nice to provide some sort of hook for picking this up, so that I can for example log it. In this case it would be great to have access to the complete Protobuf message that failed marshalling. In my case I'm getting this error when marshalling a rather large message containing a few thousands timestamps, and it's hard to decipher which one is incorrectly constructed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions