Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop @type from Connect error detail debug string #688

Merged
merged 5 commits into from
Feb 15, 2024

Conversation

jhump
Copy link
Member

@jhump jhump commented Feb 13, 2024

This makes the output of a connect-go server look more like the examples in the docs. For example, this section shows this example:

{
  "code": "unavailable",
  "message": "overloaded: back off and retry",
  "details": [
    {
      "type": "google.rpc.RetryInfo",
      "value": "CgIIPA",
      "debug": {"retryDelay": "30s"},
    }
  ]
}

However, actual output from a connect-go server would instead have a "debug" entry that looked like this:

{"@type": "type.googleapis.com/google.rpc.RetryInfo", "retryDelay": "30s"}

The type was redundantly stated as it was marshaling the google.protobuf.Any wrapper to JSON instead of the contained message.

This removes the discrepancy. Error output from a connect-go server will be a little more concise and more closely resemble the docs example with this change.

@akshayjshah akshayjshah changed the title In Connect error JSON: don't include Any's "@type" attribute Drop @type from Connect error detail's debug representation Feb 14, 2024
@akshayjshah akshayjshah changed the title Drop @type from Connect error detail's debug representation Drop @type from Connect error detail debug string Feb 14, 2024
error.go Show resolved Hide resolved
debug, err := codec.Marshal(d.pb)
if err == nil && len(debug) > 2 { // don't bother sending `{}`
wire.Debug = json.RawMessage(debug)
if wire.Value != "" { // don't bother sending `{}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd know better than me, but I think that the zero value of some of the WKTs (like timestamps) produces useful JSON output. I think we'd be okay without this check: sending the zero value of an error detail feels like an uncommon enough case that we don't need to optimize for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷, it's debatable how useful that is. But I had changed it because a value that is two or fewer characters isn't always {} with WKTs, too. While it may be a contrived (and not realistic) case, a google.protobuf.IntValue could serialize as the JSON value 1.

I guess I can change the comparison to directly compare the resulting JSON output to "{}", but had done this hoping it was a convenient way to skip the serialization step. (If you see that the value property for a WKT is "", it is intuitive enough that it's a zero value whose debug value is not particularly valuable?)

Copy link
Member Author

@jhump jhump Feb 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I just realized that a non-zero value for google.protobuf.Value could still produce {}, so it might be confusing that we just drop the debug key in this case. (Admittedly, I can't think of a legit reason to use an error detail of type google.protobuf.Value...).

But perhaps the best check is to skip the key if both wire.Value == "" && serializedJSON == "{}".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented what I put in that last comment. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my initial urge to skip sending {} was misguided. On balance, it seems better to just send the debug info, whatever it may be; I don't want to rely on end users understanding the semantics of zero values and protojson.

…pose pbInner; improve condition for when to skip debug key
Copy link
Member

@akshayjshah akshayjshah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stamping this under the assumption that the only remaining change is to send the debug details, whatever they may be (even if that's {}).

Copy link
Member

@akshayjshah akshayjshah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conformance failures expected?

@jhump
Copy link
Member Author

jhump commented Feb 15, 2024

Conformance failures expected?

@akshayjshah, sadly, yes. This will be fixed in the next release candidate of conformance tests. I noticed this happening in connect-kotlin, too, and merged a change to relax the timing of this test, to make it less likely to flake: https://github.com/connectrpc/conformance/pull/761/files#r1462481695

@jhump jhump merged commit 1f132f4 into main Feb 15, 2024
11 checks passed
@jhump jhump deleted the jh/connect-debug-info-no-at-type-attr branch February 15, 2024 02:32
@jhump jhump added the bug Something isn't working label Feb 16, 2024
@jhump jhump mentioned this pull request Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants