yarpc / yarpc-go

A message passing platform for Go
MIT License
401 stars 101 forks source link

Changed encoding/decoding error code to from InvalidArgument to Internal #2251

Open biosvs opened 3 months ago

biosvs commented 3 months ago

Functions newClientEncodingError and newServerEncodingError are called only when encoding/decoding attempt is failed, which means that either structure can't be transformed into bytes, or bytes can't be read into structure.

Currently such errors lead to CodeInvalidArgument (3) return code.

As yarpc error codes relates to grpc error codes, we may assume that meaning is also close (if not the same). In grpc-go source code the same encoding/decoding errors lead to CodeInternal code (1, 2), and so the same code should be returned in yarpc.

This PR changes CodeInvalidArgument (3) to CodeInternal(13) for most such cases.

Except for server decoding errors. If server can't decode body or header of the request, it indeed indicates that client tries to send something unexpected. (This is a change from previous review.)

It's an API change, but in a worst case we expect to have more visibility on problems that were hidden by "client errors".

biosvs commented 2 months ago

I revisited code and tests, and revert changes for server decoding: those errors indeed indicates that client sends invalid request.

codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 85.23%. Comparing base (23c069f) to head (f0ff598).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## dev #2251 +/- ## ======================================= Coverage 85.23% 85.23% ======================================= Files 270 270 Lines 15555 15557 +2 ======================================= + Hits 13258 13260 +2 + Misses 1876 1875 -1 - Partials 421 422 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.