You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by dm...@apache.org on 2022/05/18 09:38:57 UTC
[trafficserver] branch 10-Dev updated: traffic_ctl - JSONRPC: make sure we display the error regardless of the formatting type. (#8852)
This is an automated email from the ASF dual-hosted git repository.
dmeden pushed a commit to branch 10-Dev
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/10-Dev by this push:
new d1313eab7 traffic_ctl - JSONRPC: make sure we display the error regardless of the formatting type. (#8852)
d1313eab7 is described below
commit d1313eab797c2183b1c13653fbb50d6a9266384a
Author: Damian Meden <da...@gmail.com>
AuthorDate: Wed May 18 10:38:51 2022 +0100
traffic_ctl - JSONRPC: make sure we display the error regardless of the formatting type. (#8852)
- This also changesthe output style for a better quick read.
---
include/shared/rpc/RPCRequests.h | 22 ++++------------------
src/traffic_ctl_jsonrpc/CtrlPrinters.cc | 7 ++++---
2 files changed, 8 insertions(+), 21 deletions(-)
diff --git a/include/shared/rpc/RPCRequests.h b/include/shared/rpc/RPCRequests.h
index fb8e378d3..fe9221e05 100644
--- a/include/shared/rpc/RPCRequests.h
+++ b/include/shared/rpc/RPCRequests.h
@@ -203,24 +203,10 @@ operator<<(std::ostream &os, const RecordLookUpResponse::RecordError &re)
inline std::ostream &
operator<<(std::ostream &os, const JSONRPCError &err)
{
- os << "Error found.\n";
- os << "code: " << err.code << '\n';
- os << "message: " << err.message << '\n';
- if (err.data.size() > 0) {
- os << "---\nAdditional error information found:\n";
- auto my_print = [&](auto const &e) {
- os << "+ code: " << e.first << '\n';
- os << "+ message: " << e.second << '\n';
- };
-
- auto iter = std::begin(err.data);
-
- my_print(*iter);
- ++iter;
- for (; iter != std::end(err.data); ++iter) {
- os << "---\n";
- my_print(*iter);
- }
+ os << "Server Error found:\n";
+ os << "[" << err.code << "] " << err.message << '\n';
+ for (auto &&[code, message] : err.data) {
+ os << "- [" << code << "] " << message << '\n';
}
return os;
diff --git a/src/traffic_ctl_jsonrpc/CtrlPrinters.cc b/src/traffic_ctl_jsonrpc/CtrlPrinters.cc
index 25a40fd4c..aeaf20396 100644
--- a/src/traffic_ctl_jsonrpc/CtrlPrinters.cc
+++ b/src/traffic_ctl_jsonrpc/CtrlPrinters.cc
@@ -59,9 +59,10 @@ BasePrinter::write_output(shared::rpc::JSONRPCResponse const &response)
return;
}
- if (response.is_error() && this->is_pretty_format()) {
- // we print the error in this case. Already formatted.
- std::cout << response.error.as<shared::rpc::JSONRPCError>();
+ if (response.is_error()) {
+ // If an error is present, then as per the specs we can ignore the jsonrpc.result field, so we print the error and we are done
+ // here!
+ std::cout << response.error.as<shared::rpc::JSONRPCError>(); // Already formatted.
return;
}