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

clientdetails: handle error interfaces in Details somewhat #4137

Closed
wants to merge 4 commits into from

Conversation

mvo5
Copy link
Contributor

@mvo5 mvo5 commented May 8, 2024

The clienterror report has no tests right now, that is not ideal so this PR adds some.

While doing that it fixes an issue that @schuellerf discovered, i.e. that when an error interface is passed into clienterrors.Error.Details the details get lost because the json.Marshaler will not know how to handler an
error interface.

So I think this is fine to merge and will improve the current state. However I think we should rework the
clienterrors.Error so that go types will help us detect issues at compile time. With this PR we will only
detect nested errorrs at runtime and error and it will not deal with nested interface of other types.

We should probably:

  1. make clienterrors.Error a real error type, it's kinda unusual that an error does not implement the error interface.
  2. Rethink Details - AFAICT all the details will be "flattended" (via %v) after the de-serialization anyway, so we might just make details a "string". Of course testing this requires a bit of digging into the source and maybe writting some tests that validate that we indeed just use do the flattening on the other side.

@mvo5 mvo5 requested a review from schuellerf May 8, 2024 12:54
@mvo5 mvo5 force-pushed the test-clientdetails branch 3 times, most recently from 07ceb4c to bba6087 Compare May 8, 2024 13:30
@mvo5 mvo5 force-pushed the test-clientdetails branch 2 times, most recently from 6fd78c2 to c7f6fdf Compare May 8, 2024 15:08
schuellerf
schuellerf previously approved these changes May 8, 2024
Copy link
Contributor

@schuellerf schuellerf left a comment

Choose a reason for hiding this comment

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

looks pretty complete

@mvo5 mvo5 requested a review from croissanne May 13, 2024 10:33
mvo5 added 4 commits May 13, 2024 15:00
We have no tests for the clienterror, start with a trivial one.
Florian pointed out that `clienterror.Error.Details` could contain
arbitrarily deeply nested error values. Add code to detect this.

Also deal with the (common?) case that `.Details` contains a list
of errors.
@mvo5 mvo5 changed the title clientdetails: add test for error reporting clientdetails: handle error interfaces in Details somewhat May 13, 2024
Copy link
Member

@croissanne croissanne left a comment

Choose a reason for hiding this comment

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

thank you 😍

case reflect.Struct:
for i := 0; i < v.NumField(); i++ {
if err := ensureNoErrs(v.Field(i)); err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

@mvo5 Do I get this right, that only the first will be returned (same for array and map)? Is this on purpose?

Copy link
Contributor Author

@mvo5 mvo5 Jun 4, 2024

Choose a reason for hiding this comment

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

Yes, only the first is detected right now. We can change that of course, I'm not sure if it's worth it (also I'm not sure this entire PR is the right approach, it's nice in the sense that it does detect the issue now but it still will not catch other cases where we pass something to Details interface{} that is in fact an interface that is not properly serializable to json

I still wonder if we a better appraoch would be:
a) merge #4145 to fix the immedidate issue
b) change Details inteface{} -> Details string or Details []string or Details json.RawMessage (the later would force the caller to serialize). (i.e. ensure passing an err becomes a compile time error instead of a runtime error).

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure where the idea comes from that Details should be flexible but then it would be a) and b) with json.RawMessage
Starting with #4145 for now sound perfect 😏

Copy link
Contributor Author

@mvo5 mvo5 Jun 4, 2024

Choose a reason for hiding this comment

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

it's probably worth to salvage (some of) the test cases from this PR but otherwise I'm fine closing it (or closing it after (a) and (b) got done). [fwiw, (b) with json.RawMessage might become a bit annoying on the caller side, but I guess we need to try it to see how good/bad it will be :)

Copy link

github-actions bot commented Jul 5, 2024

This PR is stale because it has been open 30 days with no activity. Remove "Stale" label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale label Jul 5, 2024
Copy link

This PR was closed because it has been stalled for 30+7 days with no activity.

@github-actions github-actions bot closed this Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants