-
Notifications
You must be signed in to change notification settings - Fork 577
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
pandaproxy: Invert error_code dependencies #4722
pandaproxy: Invert error_code dependencies #4722
Conversation
Signed-off-by: Ben Pope <ben@redpanda.com>
There are currently several projects that depend on `v::pandaproxy_common` due to the conversion from `error_code` to `error_condition`, `reply_error_code` There are two ways to map to an `error_condition` 1) Override `error_category::default_error_condition` 2) Override `error_category::equivalent` 1) Is what's current, but it requires a global `default_error_condition`, but `reply_error_code` is specific to pandaproxy, so the dependency works the wrong way. 2) Could work, but only for checking equivalence of specific `std::error_code` with a specific `reply_error_code`, not for directly converting it. To break the dependency, overload `make_error_condition` that takes a `std::error_code`, and maps from `kafka::error_code` to `reply_error_condition` as before. Further commits will move code to break the dependencies. Implement replay_error_category::equivalent in terns of the new `make_error_condition`. Signed-off-by: Ben Pope <ben@redpanda.com>
Move `make_error_code` and `error_category` from pandaproxy to kafka. Signed-off-by: Ben Pope <ben@redpanda.com>
Move it from the pandaproxy::parse to pandaproxy. Change `exception_base` to use an `error_code`, which is the correct tool for passing around error information. Signed-off-by: Ben Pope <ben@redpanda.com>
Move it from the pandaproxy::json to pandaproxy. Signed-off-by: Ben Pope <ben@redpanda.com>
3c044bc
to
fd0eeb4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Needs:
- CI failures linked to issues
@@ -190,6 +191,17 @@ std::error_condition make_error_condition(std::error_code ec) { | |||
return rec::kafka_authentication_error; | |||
} | |||
return {}; // keep gcc happy | |||
} else if (ec.category() == make_error_code(pec::empty_param).category()) { | |||
switch (static_cast<pec>(ec.value())) { | |||
case pec::empty_param: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: [[fallthrough]];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to do that only for cases where there is a statement. I don't think the compiler will warn unless there is a statement, anyhow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, i thought clang-tidy warned in this case, but indeed im not see it.
Cover letter
Refactor pandaproxy errors, so that the conversion of
error_codes
toreply_error_condition
becomes the responsibility of pandaproxy, not each submodule. This makes the dependencies the right way round.There are two ways to map to an
error_condition
error_category::default_error_condition
error_category::equivalent
However:
default_error_condition
, butreply_error_code
is specificto pandaproxy, so the dependency works the wrong way.
std::error_code
with a specificreply_error_code
, notfor directly converting it.
Solution
To break the dependency, overload
make_error_condition
thattakes a
std::error_code
, and maps fromkafka::error_code
toreply_error_condition
as before. Further commits will move codeto break the dependencies.
Implement
reply_error_category::equivalent
in terns ofthe new
make_error_condition
.error_category
andmake_error_code
for kafka into kafkaerror_code
toerror_condition
code from pandaproxy::parse to pandaproxyerror_code
toerror_condition
code from pandaproxy::json to pandaproxyUseful resource: https://akrzemi1.wordpress.com/2017/09/04/using-error-codes-effectively/
Closes #4307 - this is a prerequisite of updating libfmt #4260
In a future PR, it will be possible to split the error_codes for Schema Registry and REST API.
Alternative
If
reply_error_category::equivalent
were to be implemented instead, it would something like:And then the other ~18
reply_error codes
would have to be implemented for all theerror_codes
in other namespaces such aspandaproxy::parse
,pandaproxy::json
, etc., and there would be no way to have the compiler statically check for incomplete handling of enum cases in the distant modules. In addition, conversion to an http status code would have to exhaustive switch over eachreply_error_code
., requiring two conversions.Signed-off-by: Ben Pope ben@redpanda.com
Release notes