Copilot commented on code in PR #13022:
URL: https://github.com/apache/trafficserver/pull/13022#discussion_r2991091783
##########
src/traffic_ctl/traffic_ctl.cc:
##########
@@ -33,9 +36,41 @@
#include "CtrlCommands.h"
#include "FileConfigCommand.h"
#include "TrafficCtlStatus.h"
+#include "tsutil/ts_errata.h"
// Define the global variable
-int App_Exit_Status_Code = CTRL_EX_OK; // Initialize it to a default value
+int App_Exit_Status_Code = CTRL_EX_OK; // Initialize
it to a default value
+swoc::Errata::severity_type App_Exit_Level_Error = ERRATA_ERROR;
+
+/// Determine the exit code from a JSONRPC error response by examining
+/// the severity of each errata entry. Returns @c CTRL_EX_OK when the
+/// most severe entry is below @c App_Exit_Level_Error, otherwise
+/// returns @c CTRL_EX_ERROR.
+int
+appExitCodeFromResponse(const shared::rpc::JSONRPCResponse &response)
+{
+ if (!response.is_error()) {
+ return CTRL_EX_OK;
+ }
+
+ auto err =
response.error.as<shared::rpc::JSONRPCError>();
+ swoc::Errata::severity_type most_severe =
static_cast<swoc::Errata::severity_type>(ERRATA_DIAG);
+
+ for (auto const &[code, msg] : err.data) {
+ swoc::Errata::severity_type sev(code);
Review Comment:
`appExitCodeFromResponse` can return `CTRL_EX_OK` for real JSON-RPC errors
when `err.data` is empty (e.g., protocol/decoder errors or execution errors
without errata details). Because `most_severe` is initialized to `ERRATA_DIAG`
and only updated from `err.data`, an error response with no `data` entries will
incorrectly exit 0 by default. Consider treating `err.data.empty()` as an error
(return `CTRL_EX_ERROR`), or incorporate the top-level `JSONRPCError::code`
into the decision so non-errata errors still produce a non-zero exit status.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]