Skip to content

Update BadRequest.FieldViolation richer error type #2244

@MathieuTricoire

Description

@MathieuTricoire

Feature Request

Crates

tonic-types

Motivation

Google has updated the google.rpc.BadRequest.FieldViolation message in its error model by adding two new fields: string reason and LocalizedMessage localized_message. This feature request proposes reflecting this upstream change in the tonic-types crate.

Reference:
https://github.com/googleapis/googleapis/blob/a31d216ae702a184b5b00bdece3775177dfb2cf7/google/rpc/error_details.proto#L216-L226

Proposal

  • Update the .proto files to the latest version.

  • Extend the FieldViolation struct to include two new fields:

    • pub reason: String
    • pub localized_message: Option<LocalizedMessage>
  • Update the following functions to accept two additional parameters (reason: impl Into<String> and loc_message: Option<LocalizedMessage>):

    • FieldViolation::new
    • ErrorDetails::with_bad_request_violation
    • ErrorDetails::add_bad_request_violation
    • BadRequest::add_violation

This proposal would involve modifying existing functions and therefore introduces a breaking change.

Alternatives

This is an initial proposal, and I would like to open the discussion to consider a non-breaking alternative.

Instead of modifying existing functions, we could add new functions to support the new fields. In that case, I’d appreciate input on appropriate naming conventions.

I’m happy to contribute the implementation once a direction is agreed upon. I already have a branch prepared for the breaking-change version, if you'd like to review it to get a sense of the scope 86d1095

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions