Fix scenarios where error messages aren't propagated correctly #424
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, there are three scenarios where pitaya errors aren't propagated correctly:
errors.NewError
doesn't make proper use oferrors.As
, triggering the issue.utils.GetErrorFromPayload
looks for explicit implementations, breaking polymorphism and inducing the bug.utils.GetErrorPayload
, that would convert any error to the protobuf version of a pitaya error, which would then fail to get parsed byutils.GetErrorFromPayload
For my specific case, I encountered these issues when trying to return pitaya errors in the routing function. The first one would convert it to a generic pitaya error
Internal
before returning to clients, and the other two would make error messages not propagate correctly to metrics, having errors asUnknown
in Prometheus.This MR fixes all three scenarios, with the following changes:
utils.GetErrorFromPayload
now always assumes error payloads are in protobuf schema. This is aligned with theutils.GetErrorPayload
, which always serializes with the same schema.errors.NewError
now useserrors.As
when trying to merge pitaya errors.I also took the time to improve some test cases, implement a few more and test things against pitaya-cli.
Notes:
An alternative would be to make the serialization methods use a non-protobuf schema for JSON. However, the C#
PitayaClient
always assumes errors to be in the protobuf schema, withcode
andmsg
(see here). I don't know if that was intentional, or an accidental behavior due to the previously asymmetricutils.GetErrorFromPayload
andutils.GetErrorPayload
.